473,396 Members | 1,971 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Delete does not really delete

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
Jun 27 '08 #1
4 4087
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.
I am not sure if this is in the FAQ (have you looked?) but about once
a month we get this question. Please post to the newsgroup that deals
with your platform. Whatever "performance monitor" tells you cannot
have anything to do with the language, and everything to do with your
OS.

Your guess about "heap allocator" and its relation to "future use" of
"deleted memory" is about as good as mine. Any way to "force the
release" would certainly be plaform-specific, don't you think?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 27 '08 #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.
Jun 27 '08 #3
Juha Nieminen <no****@thanks.invalidkirjutas:
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
At least the C++ implementatons and OS-es I have used do reduce the
process memory (Windows and Linux). There is some granularity though, it
used to be 1MB in Windows IIRC.
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.)
That's what the virtual address space is for. Maybe the typical size of a
single allocation also plays a role, if you have a single byte allocated
in each hardware memory page (4096 bytes for x86 IIRC), then you really
can't release any of them.
>
Thus in most OS's the memory taken by programs never decreases. OTOH
that's what swapping is for.
We routinely monitor the program workset memory as seen by OS and it
definitely decreases and increases (with megabyte granularity, but that's
ok for us).
>
>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.
I bet the problem is somewhere else.
>
The default allocator used in C and C++ programs will reuse heap
memory whenever it can. That's not the problem.
That's true.

Best
Paavo

Jun 27 '08 #4
On Jun 2, 7:12*pm, Hong Chen <HongChe...@gmail.comwrote:
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
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: | last post by:
Hi all, I've been using C++ for quite a while now and I've come to the point where I need to overload new and delete inorder to track memory and probably some profiling stuff too. I know that...
20
by: Ioannis Vranos | last post by:
When we use the standard placement new operator provided in <new>, and not a definition of owr own, isn't a call to placement delete enough? Consider the code: #include <new>
15
by: Roy Smith | last post by:
I understand that "delete xp" deletes a scalar object and "delete xp" deletes an array of objects, but what I don't understand is why you need to tell the compiler which you're doing. When you...
16
by: robert | last post by:
been ruminating on the question (mostly in a 390/v7 context) of whether, and if so when, a row update becomes an insert/delete. i assume that there is a threshold on the number of columns of the...
2
by: Bob Tinsman | last post by:
This problem shows up in Firefox 1.5.0.1 and Rhino 1.6R2. I've found that if I have an XML node expression that ends in a filter, I can't use it with the delete operator. In the following...
29
by: Jon Slaughter | last post by:
Is it safe to remove elements from an array that foreach is working on? (normally this is not the case but not sure in php) If so is there an efficient way to handle it? (I could add the indexes to...
15
by: LuB | last post by:
I am constantly creating and destroying a singular object used within a class I wrote. To save a bit of time, I am considering using 'placement new'. I guess we could also debate this decision -...
19
by: Daniel Pitts | last post by:
I have std::vector<Base *bases; I'd like to do something like: std::for_each(bases.begin(), bases.end(), operator delete); Is it possible without writing an adapter? Is there a better way? Is...
8
by: Rahul | last post by:
Please read the following code class Test{ public: void * operator new (size_t t) { return malloc(t); } void operator delete (void *p) { free(p); } };
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.