Re: freeing memory in programs [message #3928] |
Thu, 23 March 1995 15:06  |
rivers
Messages: 228 Registered: March 1991
|
Senior Member |
|
|
In article <3ks2kr$ioo@dux.dundee.ac.uk>, pjclinch@dux.dundee.ac.uk (Pete Clinch) writes:
>
> I'm writing a Wave Widgets program that uses some big arrays (256 * 256 *
> 128 MRI image stacks). Some operations require temporary arrays to hold
> significant chunks of this, but I don't want these arrays around full
> time to choke the memory. I can't use DLEVAR as I'm not at the main
> program level, so how do I free up memory? If I had assigned an array
> by, say
>
> TmpArr = MAKE_ARRAY(256,256,128, /INT)
>
> would a subsequent use of something like TmpArr = BYTE(0) or
> TmpArr = MAKE_ARRAY(1) free up the memory, or would it still be taken up
> but no longer accessible?
>
I will free it up for re-use inside IDL. IDL does not return the memory to the
operating system, i.e. those pages remain in the virtual memory your process is
using. If you later allocate another big array inside IDL you will reuse the
memory you previously released. HOWEVER, if you know that you will later be
needing an array of exactly the same size you are better of NOT freeing up the
memory. This is because IDL will fragment the memory you release (allocating
small variables, etc.), and when you need it again there won't be a chunk which
is big enough. IDL will then have to ask OS for more memory, and eventually you
will run out.
____________________________________________________________
Mark Rivers (312) 702-2279 (office)
CARS (312) 702-9951 (secretary)
Univ. of Chicago (312) 702-5454 (FAX)
5640 S. Ellis Ave. (708) 922-0499 (home)
Chicago, IL 60637 rivers@cars3.uchicago.edu (Internet)
|
|
|
Re: freeing memory in programs [message #3930 is a reply to message #3928] |
Fri, 24 March 1995 02:01  |
Fergus Gallagher
Messages: 41 Registered: January 1995
|
Member |
|
|
> Subject: freeing memory in programs
> Date: 23 Mar 1995 15:03:55 -0000
> From: pjclinch@dux.dundee.ac.uk (Pete Clinch)
> Organization: The University, Dundee, DD1 4HN, Scotland, UK.
> Newsgroups: comp.lang.idl-pvwave
>
> I'm writing a Wave Widgets program that uses some big arrays (256 * 256 *
> 128 MRI image stacks). Some operations require temporary arrays to hold
> significant chunks of this, but I don't want these arrays around full
> time to choke the memory. I can't use DLEVAR as I'm not at the main
> program level, so how do I free up memory? If I had assigned an array
> by, say
>
> TmpArr = MAKE_ARRAY(256,256,128, /INT)
>
> would a subsequent use of something like TmpArr = BYTE(0) or
> TmpArr = MAKE_ARRAY(1) free up the memory, or would it still be taken up
> but no longer accessible?
There is the help,/mem command to help you with this. I *suspect* that it
depends on the other memory that's been allocated in the meantime. The
memory is almost certainly available but, generally, in a non-contiguous
block wrt other memory on the heap.
Strangely,
IDL> tmp = intarr(1000,1000) ; say
IDL> print,temporary(tmp)
Help,/mem shows that memory has still been 'lost' in this case.
Note that here I have used an alternative way of 'deallocating' a variable.
(I seem to remember reading somewhere that it is preferable to tmp=0)
Fergus
=================================================
| Fergus Gallagher |
| Remote Sensing Applications Development Unit |
| British National Space Centre |
| Monks Wood |
| Huntingdon PE17 2LS / UK |
| |
| F.Gallagher@nerc.ac.uk |
| http://uh.nmt.ac.uk/bnsc/fgg.html |
=================================================
|
|
|