• Advertisement

Archived

This topic is now archived and is closed to further replies.

freeing memory

This topic is 5850 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

how does one go about freeing memory taken up by an array of pointers for example: char* text[4096]; I didn''t dynamically allocate the memory for it, so how do I then free it?

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by element2001
I didn''t dynamically allocate the memory for it, so how do I then free it?

If you didn''t allocate anything, you don''t have to free anything.

Share this post


Link to post
Share on other sites
K thanks, the only reason I ask is because system resources drop when the program is running, but when it is closed they don''t return. For example lets say my sys resources are at 80%, then drop to 74% then stay at 74% when the program is closed. But when any other application runs and is closed the system resources return back to 80%, so it seemed as if I was doing something wrong in not freeing up the RAM

Share this post


Link to post
Share on other sites
most likly some gdi resources that are not being freed. make sure when using gdi resources (HBITMAPS, HFONTS, etc) that you always DeleteObject() them.


  
// proper way to select gdi object and to delete it

// so you got something like

HBITMAP myBmp = CreateBitmap();
HDC myDC = CreateCompatibleDC();
HBITMAP = oldBmp;
// save old bitmap handle, otherwise we cant properly delete

// our bitmap

oldBmp = (HBITMAP)SelectObject(myDC, myBmp);

// later on when done with the bitmap and the dc

SelectObject(myDC, oldBmp);
DeleteObject(myBmp);
DeleteDC(myDC);

// if you select mulitple bmps into the dc

// then you only save the first one, since that is the default

// HBITMAP that windows creates/deletes when a HDC is

// created/deleted



hopefully that makes sense. now on to your array of pointers which i assume you

  
for(i=0; i<4096; i++)
{
//if created with malloc

free(text[i]);
// or if new''d

delete text[4096];
}


the actual array gets freed when the app exits since it is actually stored in the executable data section, and is never actually allocated.

Share this post


Link to post
Share on other sites

  • Advertisement