Click here to Skip to main content
15,907,497 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: memory leaks Pin
Bernhard19-Nov-01 3:08
Bernhard19-Nov-01 3:08 
GeneralRe: memory leaks Pin
Alvaro Mendez19-Nov-01 11:09
Alvaro Mendez19-Nov-01 11:09 
GeneralRe: memory leaks Pin
Derek Waters19-Nov-01 14:13
Derek Waters19-Nov-01 14:13 
GeneralRe: memory leaks Pin
Bernhard19-Nov-01 19:21
Bernhard19-Nov-01 19:21 
Generalthanx Pin
luckylourson19-Nov-01 23:14
luckylourson19-Nov-01 23:14 
GeneralRe: thanx Pin
Bernhard19-Nov-01 23:24
Bernhard19-Nov-01 23:24 
GeneralRe: memory leaks Pin
Alvaro Mendez20-Nov-01 8:22
Alvaro Mendez20-Nov-01 8:22 
GeneralRe: memory leaks Pin
Rassman20-Nov-01 5:56
Rassman20-Nov-01 5:56 
Though I go along with the others, specially the likes of bounds checker, I tend to build in a bit of quicky debugging. Afteral, you get told you have memory leaks so all you need to know is 'can my code exit without passing the cleanup' and 'does my clean up clean them all'.

Typically a node creation/deletion will follow the same few paths. If none of your memory is freed then that will be pretty obvious to fix, if only some are not freed then it is likely to be a program path problem

So, I count them in and count them out in the debug. Then print the debug value.

For example, lets say I have something like this below that is part of a xml scema parser. I have global counters,

#ifdef TRACE_TREE_MEMLEAKS
long m_Count_Tree_Leaks;
#endif

const int IN_SCHEMA_TREE = 1;
const int IN_XML_TREE = 0;
void SchemaTree::StoreSingleLineRootItem(LPCTSTR Line, int WhichTree)
#ifdef TRACE_TREE_MEMLEAKS
//include at every insert point. I had 5 ways into my two trees.
++m_Count_Tree_Leaks;
#endif
ElementTypeTree* ETType = new ElementTypeTree;
CString sLine, lSearchFor;

//fill item details

if(WhichTree == IN_SCHEMA_TREE)
m_DataTree.InsertDataItem(ETType,NULL);
else
m_XMLTree.InsertDataItem(ETType,NULL);
}

The multiline element type can create none or many subelements, so I would have these counted in too.

void SchemaTree::StoreMultiLineRootItem(int TreeLevel, LPCTSTR ItemString)
{
static CString RootItemName;
ElementTypeTree* ETType;
SubElements* subType;
CString sLine, lString, lSearchFor;
#ifdef TRACE_TREE_MEMLEAKS
//include at every insert point. I had 5 ways into my two trees.
++m_Count_Tree_Leaks;
++m_Count_Tree_Sub_Leaks;
#endif
ETType = new ...
subType = new ...

Then use
#ifdef TRACE_TREE_MEMLEAKS
--m_Count_Tree_Leaks;
--m_Count_Tree_Sub_Leaks;
#endif
at each point there are deleted.

I put this sort of stuff in from the beginning, it easy then, your not likely to miss one.

printing the debug counters values before exit (each possible exit) will tell you you have memory leaks, and which of your structures in is doing it.




We do it for the joy of seeing the users struggle.
GeneralEmbedded ActiveX control Pin
RaviRao18-Nov-01 22:20
RaviRao18-Nov-01 22:20 
GeneralRe: Embedded ActiveX control Pin
Rassman19-Nov-01 2:50
Rassman19-Nov-01 2:50 
GeneralAdding Hot spot to help ! Pin
Hadi Rezaee18-Nov-01 20:29
Hadi Rezaee18-Nov-01 20:29 
GeneralRe: Adding Hot spot to help ! Pin
Roger Allen19-Nov-01 5:26
Roger Allen19-Nov-01 5:26 
GeneralRe: Adding Hot spot to help ! Pin
Hadi Rezaee19-Nov-01 7:59
Hadi Rezaee19-Nov-01 7:59 
GeneralRe: Adding Hot spot to help ! Pin
Roger Allen19-Nov-01 23:26
Roger Allen19-Nov-01 23:26 
GeneralRe: Adding Hot spot to help ! Pin
Hadi Rezaee20-Nov-01 1:05
Hadi Rezaee20-Nov-01 1:05 
GeneralHelp Context icon ... Pin
Hadi Rezaee18-Nov-01 20:26
Hadi Rezaee18-Nov-01 20:26 
GeneralRe: Help Context icon ... Pin
Roger Allen19-Nov-01 5:38
Roger Allen19-Nov-01 5:38 
GeneralRe: Help Context icon ... Pin
Hadi Rezaee19-Nov-01 6:53
Hadi Rezaee19-Nov-01 6:53 
GeneralCEdit subclassing Pin
Nick Blumhardt18-Nov-01 19:42
Nick Blumhardt18-Nov-01 19:42 
GeneralRe: CEdit subclassing Pin
luckylourson18-Nov-01 23:24
luckylourson18-Nov-01 23:24 
GeneralRe: CEdit subclassing Pin
19-Nov-01 12:39
suss19-Nov-01 12:39 
GeneralRe: CEdit subclassing Pin
luckylourson19-Nov-01 22:38
luckylourson19-Nov-01 22:38 
GeneralOne more question.. This is really buging me! Pin
RobJones18-Nov-01 13:56
RobJones18-Nov-01 13:56 
GeneralRe: One more question.. This is really buging me! Pin
Christian Graus18-Nov-01 14:29
protectorChristian Graus18-Nov-01 14:29 
GeneralRe: One more question.. This is really buging me! Pin
RobJones18-Nov-01 14:48
RobJones18-Nov-01 14:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.