Jump to content
  • Advertisement
Sign in to follow this  
Alessandro

C++: memory deallocation

This topic is 2586 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

Hi, I surely misunderstood something about dynamic memory allocation and deallocation. I have this simple code that fills a dynamic array with values:

float *map;
int iterations=9999999;
map = new float[iterations];
for (int i=0; i<iterations; i++)
{
map=someRandFloat();
}

The above routine uses about 40MB of memory. After that, I'd like to deallocate and free the memory, and so I run:



delete map;


However, the Task Manager shows that the program is still using the same 40MB of memory.
Thanks

Share this post


Link to post
Share on other sites
Advertisement
That said, Task Manager isn't a good way to measure memory usage. In somewhat oversimplified terms, it tells you how much memory the operating system has given to your program, not how much memory your program is actually using.

Share this post


Link to post
Share on other sites

That said, Task Manager isn't a good way to measure memory usage. In somewhat oversimplified terms, it tells you how much memory the operating system has given to your program, not how much memory your program is actually using.


Oh, I see. Then probably is better to use some other tools to check memory usage. I'm on OSX, but I need to debug my application also in WIndows. What do you actually use (if any) to check memory footprint?

Share this post


Link to post
Share on other sites
to verify the memory is actually free try doing something like

for(int i=0; i<100; i++)
{
auto temp = new int[100000];
printf("mem @ %p\n", temp);
delete [] temp;
}

you can see that it does not continue to consume more and more memory, however in task manager you might see it jump up and not go right back down.

Share this post


Link to post
Share on other sites

[quote name='SiCrane' timestamp='1320944117' post='4882653']
That said, Task Manager isn't a good way to measure memory usage. In somewhat oversimplified terms, it tells you how much memory the operating system has given to your program, not how much memory your program is actually using.


Oh, I see. Then probably is better to use some other tools to check memory usage. I'm on OSX, but I need to debug my application also in WIndows. What do you actually use (if any) to check memory footprint?
[/quote]

Process Explorer is a good start.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!