[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about top




On Thu, 2 Aug 2001, Miki Shapiro wrote:

> I traced the leak to a 1MB buffer I allocate using new.
> when I do:
> delete [] pBuffer
> It stays registered as allocated memory.

how do you know that?

you should realize that when you free memory in C/C++, it does not get put
back to the free memeory pool of the OS - it is still allocated to the
process. virtual memory usage in this manner is increased - but never
decreased. on the next allocation of the buffer - the same free memory
will be re-used, unless part of it was meanwhile allocated for another
purpose, in which case your overal memoery usage will increase. this has
got to do with fragmentation.

i suggest that you make a small program that demonstrates the problem (and
check that it indeed does so) and send it over - then we'll be able to
look, and all be smarter.

you coudl use another approach - of not freeing and allocating such large
buffers all the time. keep the buffer allocated, and only re-use it when
you need it again. it also will enhance performance of your program,
CPU-wise.

please note that it is quite rare to taccle on OS problems - usually the
fault is with one's code. i did encounter OS bugs while coding - but these
were rare cases - perhaps once every 6 month, with a very large project -
and that was on solaris, not on linux.

--
guy

"For world domination - press 1,
 or dial 0, and please hold, for the creator." -- nob o. dy


=================================================================
To unsubscribe, send mail to linux-il-request@linux.org.il with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail linux-il-request@linux.org.il