1

I'm allocating memory using new as and when I receive data in one of my methods and in the destructor, I'm releasing all the allocated memory using delete.

However, after releasing the memory, from the task manager, when I look at mem usage under the process tab, the memory usage still remains the same. It doesn't give an impression that the memory is being released.

So, when does the memory actually get released? And what is the best way to find out the actual memory being used by a process.

Thanks

B Faley
  • 17,120
  • 43
  • 133
  • 223
nsivakr
  • 1,565
  • 2
  • 25
  • 46

2 Answers2

2

In most cases, it's never given back to the OS while the app is running. Afterwards, of course, all resources are recovered by the OS.

[Edited after the comments rightly pointed out that 'never' is a long time ...]

smparkes
  • 13,807
  • 4
  • 36
  • 61
0

The OS allocates a default heap to your application. This heap is allocated during the initialization of your process. Thus, your new's and delete's won't affect the bar you see in the task manager.

However, if you try to initialize a big buffer and the allocated heap isn't enough, the OS will allocate more memory for your application - and this should be reflected in the task manager...

MindBlower
  • 65
  • 8