comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » freeing memory in programs
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Freeing memory [message #7026 is a reply to message #3933] Fri, 13 September 1996 00:00 Go to previous messageGo to previous message
Christian Soeller is currently offline  Christian Soeller
Messages: 46
Registered: August 1996
Member
Phil Williams <williams@irc.chmcc.org> writes:

> My question is why? And why is there very little descrpancy in the
> help,/mem for the heap used? The sysmon looks like alot more than a 1%
> difference?
It is because of the way that memory allocation in a process under unix works.
Following example, from an freshly started idl process:

IDL> i=fltarr(1000000)
IDL> help,/mem
heap memory in use: 4075014, calls to MALLOC: 138, FREE: 36

ps -el for the process:
30 S 1115 21705 21701 0 26 20 * 3070:1673 8838e3e0 pts/0 0:01 idl
i.e. Unix tells you that the process uses 3070 blocks of memory (1673 in
physical RAM)

But then say in IDL
IDL> i=0
IDL> help,/mem
heap memory in use: 74976, calls to MALLOC: 140, FREE: 37

Now ps -el tells you
30 S 1115 21705 21701 0 26 20 * 3070:1676 8838e3e0 pts/0 0:01 idl
i.e. still the same amount of memory is used by the process, even more is now
in physical RAM.

The paradox is resolved by knowing that memory that has been returned by IDL
(internally using some equivalent of the free (3C) function from the
allocation library) is not(!) being returned to the operating system but
merely put in the list of free blocks maintained by the allocation library
routines. Here is what the info of the GNU allocation library tells you:

> Occasionally, free can actually return memory to the operating system
> and make the process smaller. Usually, all it can do is allow a later
> later call to malloc to reuse the space. In the meantime, the space
> remains in your program as part of a free-list used internally by
> malloc.


So, if you have a temporary computation that uses a *huge* amount of memory
you will still see that in sysmon after the associated memory has been
internally freed and the heap memory in IDL looks much smaller. Another
related issue is memory fragmentation...
Obviously, if you restart the process from scratch and restore only the saved
variables you won't incurr these costs.

Regards,

Christian

------------------------------------------------------------ --------
Christian Soeller mailto: csoelle@sghms.ac.uk
St. Georges Hospital Medical School Dept. of Pharmacology
Cranmer Terrace London SW17 0RE
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Slide_Image (widget_draw) Scollbar-Position ?
Next Topic: labview news group

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Nov 28 21:36:13 PST 2025

Total time taken to generate the page: 0.87954 seconds