Problem with delete[] in class destructor

Nicolas Wack nwack@iua.upf.es
Tue Mar 22 12:11:00 GMT 2005


I'm watching the memory consumption with 'top' (that's the reason for 
the call to sleep)
However if I change the allocation to new float[] instead of new Test 
and then free it, it gets directly freed. (see attached file)

What's weird is that if I launch the original program a second time 
while the first already has supposedly freed its memory, it eats 
everything and bring my box to its knees, killing most of the processes 
that use memory (so I guess the memory is not freed at all).

Also, top tells me that the whole memory stays resident (which means it 
doesn't even return to the program's free memory pool, am I right?)

Nicolas.

Nathan Sidwell wrote:
> Nicolas Wack wrote:
> 
>> Hi all!
>>
>> I have a little problem, and I thought maybe someone could help me out 
>> before I go crazy!!
>> Here's a simple file that allocates some amount of memory (roughly 
>> 300MB), sleeps for 5 secs, deallocates it and sleeps for 15 seconds.
>>
>> I know for sure that the program goes through all the destructors, 
>> however nothing gets freed...
> 
> 
> define 'freed'.  Do you mean
> 1) returned to the program's free memory pool?
> 2) returned to the OS?
> 
> Unless you do something system specific, #1 is what will happen (because
> that's what the standard says should happen)
> 
> nathan
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mem_v2.cpp
Type: text/x-c++src
Size: 343 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20050322/f4851dc7/attachment.bin>


More information about the Gcc-help mailing list