Delete does not really delete

Discussion in 'C++' started by Hong Chen, Jun 3, 2008.

  1. Hong Chen

    Hong Chen Guest

    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
    Hong Chen, Jun 3, 2008
    #1
    1. Advertising

  2. Hong Chen wrote:
    > 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.
    Juha Nieminen, Jun 3, 2008
    #2
    1. Advertising

  3. Hong Chen

    Puppet_Sock Guest

    On Jun 2, 7:12 pm, Hong Chen <> wrote:
    > 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
    Puppet_Sock, Jun 16, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Amir
    Replies:
    3
    Views:
    583
  2. nc
    Replies:
    1
    Views:
    482
    nice.guy.nige
    Feb 3, 2005
  3. Replies:
    2
    Views:
    326
  4. Jeannie
    Replies:
    15
    Views:
    872
    Jeannie
    Aug 30, 2005
  5. =?Utf-8?B?TFc=?=
    Replies:
    8
    Views:
    397
    =?Utf-8?B?TFc=?=
    Apr 25, 2007
Loading...

Share This Page