On Thursday 13 May 2010, Akhthar Parvez K wrote: > On Thursday 13 May 2010, Shlomi Fish wrote: > > Then it is very likely that the memory allocated to the "mem" pointer will > > not > > be returned to the kernel due to the nature of malloc() and how it is an > > abstraction above sbrk(): > > > > http://linux.die.net/man/2/sbrk > > > > perl 5 makes use of sbrk eventually as well (either by using the libc > > malloc() > > or by implementing its own). Note that for very large allocations, perl may > > use mmap() instead of sbrk() in which case the memory may get released. > > I've > > seen it in a demonstration program that someone pasted on IRC, a few years > > back. > > Yes, I think the memory space allocated by a process using malloc() can't be > really freed up until the calling process is terminated. And processes that > uses mmap() can unmap those chunk size of memory when it's not needed. I > guess Perl by default allocates memory using malloc() and changes the memory > allocated using sbrk(). So how does Perl know it has to mmap() instead if the > (huge) size was being used incrementally (not at once)? I now believe the > only way to free up the space used by a small portion of your program is > forking that part of the program so that it will run as a child process and > return all the memory used by it back to the system. Please correct me if I > am wrong.
It looks like the memory that is freed (ie, not being used any more) by a process can be used by other processes, right? I think the *nix OS lets other processes to use these freed pages by moving them to swap. -- Regards, Akhthar Parvez K http://Tips.SysAdminGUIDE.COM UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity - Dennie Richie -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/