> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Baruch Even
> Sent: Tuesday, October 03, 2006 12:59 PM
> To: [email protected]
> Subject: Re: "free" does not frees memory ?
> 
> * Baruch Even <[EMAIL PROTECTED]> [061003 12:16]:
> > * Michael Sternberg <[EMAIL PROTECTED]> [061003 09:21]:
> > > From man page of "free" on Solaris 8:
> > > 
> > > The argument to free() is a pointer to  a  block  previously 
> > > allocated  by malloc(), calloc(), or realloc(). After free() is 
> > > executed, this space is made available for further  allo- 
> cation  by  
> > > the application, though not returned to the sys- tem. Memory is 
> > > returned to the system only upon  termination of  the  
> application.
> > > 
> > > Two questions:
> > > 
> > > 1. What the situation in Linux ? Is "free" returns memory to OS ?
> > > 2. If not - what the proper call to "flush" memory back to OS ?
> > 
> > The behaviour of free() depends on the libc that you use, a 
> sane libc 
> > will not return the memory to the OS except in special cases.
> 
> This contradicts what I wrote later on that glibc will return 
> memory to the OS when possible. It happens when you research 
> the details for the answer while you write it. Though I 
> expect that in most usage cases memory will not be returned 
> simply because it is impossible to do so.
> 

It depends on the compiler policy, the method of allocation, where the free
memory is (fragmentation) and it's size.

I very fuzzy of the details (it's been a very long time since I dealt with
things at that level). IIRC glibc allocates
memory by increasing the size of the data segment (the size of the data pool of
the program). When several
of blocks are allocated dynamically and then freed, whole can occur which are
later reused, which can cause
memory fragmentation and inhibit freeing up the memory (smart allocation orders
can enable the program to
better free up memory).

> Baruch
> 
> =================================================================
> To unsubscribe, send mail to [EMAIL PROTECTED] 
> with the word "unsubscribe" in the message body, e.g., run 
> the command echo unsubscribe | mail [EMAIL PROTECTED]
> 
>  
>  +++++++++++++++++++++++++++++++++++++++++++
>  This Mail Was Scanned By Mail-seCure System  at the Tel-Aviv 
> University CC.
> 


=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to