Advertisement

deleting in the right order.

Started by January 16, 2002 08:38 PM
6 comments, last by Mardigin 22 years, 11 months ago
I know that you are suppose to delete in the opposite order theat you allocate, but what happens if you do not? I tried it in the wrong order and things seemed to run fine. Will I have a bad memory leak if I delete out of order?
Delete what in the wrong order? The order matters with some things, it doesn''t with others.

[Resist Windows XP''s Invasive Production Activation Technology!]
Advertisement
You''re probably confused by the fact that you''re supposed to release COM objects in the reverse order they were acquired. Memory is totally different.

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!
I did not know that it matters with some things and not others. How will I know what it matters with and what it does not matter with?
ahh Oluseyi you are right. It was COM obj I was looking at. So for allocating memory to a char array I don''t have to worry about order, but just for COM? Thank you.
ahh Oluseyi you are right. It was COM obj I was looking at. So for allocating memory to a char array I don''t have to worry about order, but just for COM? Thank you.
Advertisement
Well, some cases you do ie
  typedef struct sList{    int iData;    struct sList *pNext;} tList;//code{    tList *pList;    pList = (tList *)malloc(sizeof(tList));    pList->iData = 0;    pList->pNext  = (tList *)malloc(sizeof(tList));    // do something    free(pList);    free(pList->pNext); // oops!}  


Can''t free the head pointer, then try to free the children. Just an example for the new guys.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

Actually I believe it is generally a good idea to try and free memory in reverse order - you get less fragmentation and therefore more efficient use of memory.

But it isn''t essential, unless you are using com or classes/structures that rely on one another.

This topic is closed to new replies.

Advertisement