Re: [gtk-list] Re: Unix Memory Management : Clearing up a few misconceptions (was Re: how can I trust glib when it has so manymemleaks?)



Guillaume Laurent wrote:
> 
> Michael Babcock <mbabcock@la.creatureshop.henson.com> writes:
> 
> > Guillaume Laurent wrote:
> 
> [...]
> 
> > > UNDER UNIX, WHEN YOU FREE() MEMORY, IT IS NOT RELEASED TO THE OS. THE
> > > SIZE OF YOUR PROCESS WON'T EVER SHRINK, IT CAN ONLY INCREASE.
> 
> (BTW, shouting was not my intent here, just trying to make my point
> fairly visible. My apologies to all. Note also that I voluntarily made
> a sweeping statement, I'm quite aware that this is not always
> true. However, it is true most of the time).
> 
> > I just did some tests to confirm that I'm not going insane, and yes
> > free() DOES return the memory. I tested X (open and close netscape),
> > emacs (load and kill a large buffer) and a trivial program of my own
> > that just calls malloc(), then free() a bit later. Even if X and Emacs
> > was doing something weird, my test program wasn't.
> 
> > According to "ps axm" the SIZE of the process does shrink. Dramatically.
> > Is ps not a valid way to determine the memory allocated to a process?
> 
> It is, but while I'm not surprised about X and Emacs (which have
> "advanced" mem management schemes), I'd like to see your test program,
> because I could not reproduce this. What amount of memory are you
> allocating ?
> 
> > So maybe this isn't guaranteed by any standard, but its not like I have
> > some oddball system here: Debian 2.1 (glibc 2.0).
> 
> I use glibc 2.0 too.

Nothing fancy:

#include <iostream>

int main () {
    char * c = new char[10000000];

    for (int i = 0; i < 10000000; i++)
        c[i] = i;

    cout << "type a key" << endl;

    char ch;
    if (cin >> ch)
        delete [] c;

    while (true)
        ;

    return 0;
}

Before I type a key the memory usage is 10MB, after it is about 400K.

--
Michael Babcock
Jim Henson's Creature Shop - Los Angeles
mbabcock@la.creatureshop.henson.com



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