   How to debug Templated Classes
  I have this singleton class, which is templated, and I have refcount implemented on the class, which gets incremented/decremented on the constructor/destructor...Unfortunately something doesnt seem to be working correctly, and I need to debug it...... the problem arises from the fact that there are n classes that could be the "callers" of the template...How do i debug it? How do I know what i am working with?Thanks for any tips on this...   [Hugo Ferreira][Positronic Dreams][Colibri 3D Engine][Entropy HL2 MOD]    [Yann  L.][Enginuity]  [Penny Arcade]  [MSDN][VS  RoadMap][Humus][BSPs][UGP][NeHe]"I say we take off and nuke the entire site from orbit. It''s the only way to be sure." 
  Debug it like any other class. In this case I would start by putting a breakpoint on the function that uses the template and then step in manually. If that fails, you can always scatter a few breakpoints inside and watch the call stack window to determine which particular template instantiation you are looking at. ;  I''ve been using that method, but there is a master class which is a global, and instantiates a bunch of singletons, and i think the mem leak in my engine is coming from on of those singletons, and it would be invaluable to locate which class it is... but the class is hidden inside the "T"....   [Hugo Ferreira][Positronic Dreams][Colibri 3D Engine][Entropy HL2 MOD]    [Yann  L.][Enginuity]  [Penny Arcade]  [MSDN][VS  RoadMap][Humus][BSPs][UGP][NeHe]"I say we take off and nuke the entire site from orbit. It''s the only way to be sure." ;  Can''t you just use the call stack to find the original calling specialization? ;  finding memory leaks is definitely a pain in the butt.  you can try some more involved methods like overloading the new & delete operator globally and having them log to a file the type of object they are creating.  you can run a few frames and then parse the log to see which, if any, objects are being created but not deleted.  that can get a little messy and won't always be so easy to get the information out of that you want to get out.you could go a more accurate but far more annoying route of writing dummy test type code which only instantiates a single object of a single type, do work on it, and see if there was a memory leak.also you can just throw some sanity checks in the destructors of all your classes that inherit from the template (and in the template itself) to make sure that everything is getting delete'd.  another super easy and very important thing woulc be to make all member variables of the template and it's children private or protected so that you can be sure that no one other than the classes themselves are messing with the memory allocation.   also watch out for static variables in base classes b/c all children will use the same instance of the static variable (children don't get their own static).  also, set all pointers to NULL after you "delete" them so that anyone else trying to access that memory will get exceptions thrown (won't really help find a memory leak but since you'll be in that code anyway...)-me   [edited by - Palidine on February 4, 2004 4:11:48 PM];  hmmm.... Im using Fluid Studios'' mem leak tracer, so i have a fair amount of data to work from...I''ve noticed that the call stack window says which of the Template instances im stepping through, something i hadnt noticed before, thanks for the tips...The Reference Counter is acting up on classes that have a singleton of themselfs, like:class a{csingleton< a >   cs_a;};something i must look into carefuly... [Hugo Ferreira][Positronic Dreams][Colibri 3D Engine][Entropy HL2 MOD]    [Yann  L.][Enginuity]  [Penny Arcade]  [MSDN][VS  RoadMap][Humus][BSPs][UGP][NeHe]"I say we take off and nuke the entire site from orbit. It''s the only way to be sure." 