Delete does not really delete

H

Hong Chen

I developed a large program and found the program does not really
release memory after the delete operation is taken, since, according
to "performance monitor", the virtual bytes used by this process does
not decrease after 'delete'.

Is this because the heap allocator holds the deleted memory for future
use? Is there anyway to force the release of the memory since we
confront problem of memory allocation failure if the delete memory is
not really released.

Goshiwen
 
J

Juha Nieminen

Hong said:
I developed a large program and found the program does not really
release memory after the delete operation is taken, since, according
to "performance monitor", the virtual bytes used by this process does
not decrease after 'delete'.

In most OS's, when you allocate memory the program asks the OS to
increase the heap for the process. It never asks it to reduce it. (And
even if in some OS programs would have the means to do that, memory
fragmentation would probably often stop them from being able to do it.)

Thus in most OS's the memory taken by programs never decreases. OTOH
that's what swapping is for.
Is this because the heap allocator holds the deleted memory for future
use? Is there anyway to force the release of the memory since we
confront problem of memory allocation failure if the delete memory is
not really released.

The default allocator used in C and C++ programs will reuse heap
memory whenever it can. That's not the problem.
 
P

Puppet_Sock

I developed a large program and found the program does not really
release memory after the delete operation is taken, since, according
to "performance monitor", the virtual bytes used by this process does
not decrease after 'delete'.

Is this because the heap allocator holds the deleted memory for future
use? Is there anyway to force the release of the memory since we
confront problem of memory allocation failure if the delete memory is
not really released.

There is also the possibility your freestore is fragmented.
If there are deleted chunks of memory in the middle of
the freestore, it is unlikely these will be given back
to the OS. Indeed, in extreme situations, you can wind
up walking your freestore and running out of memory when
you only have a very small amount of actually-used memory.

You can sometimes get a profiling tool to detect such
situations. (Though it's off topic here. Ask in a news
group dedicated to your compiler and operating system.)
If that is the case, and it is a problem, there are many
ways to approach the situation. For example, you can take
more direct control of memory allocation, in such ways
as allocating a bunch of a particular object, then you
can re-use them as needed. Such things as a the named
ctor idiom are good places to start your research.
Socks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top