Memory Leak [message #67393] |
Mon, 27 July 2009 15:05 |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
Today's quiz is to write a short program to make IDL leak memory
without using any pointer variables or external calls.
In the program test.pro below, I read a data file containing 0b values
into a structure with a length one blank string tag. After each
call to test.pro I print the fourth element of the memory() function,
which is supposed to give the "maximum amount of dynamic memory used
since the last time the MEMORY function was called."
IDL> print,!version
{ x86 linux unix linux 7.0 Oct 25 2007 32 64}
IDL> print,(memory())(3)
778166
IDL> test1 & print,(memory())(3)
3673008
IDL> test & print,(memory())(3)
4273023
IDL> test & print,(memory())(3)
4873023
As one can see, the highwater mark for memory usage keeps increasing,
even though no variables are being added to the main level.
Evidently, memory is leaking during the conversion from 0b to a length
one blank string (which gets converted to an empty string).
(No, I am not a masochist doing this for fun -- this memory leak is
causing problems with an IDL FITS reader (mrdfits.pro) that I am
trying to maintain....)
Cheers, --Wayne
pro test
a = {a1:3b,a2:0b,a3:4b}
a = replicate(a,100000)
openw,lun,'test.dat',/get_lun
writeu,lun,a
close,lun
openr,lun,'test.dat'
out = {a1:0b,a2:' ',a3:0b}
out = replicate(out,100000)
readu,lun,out
free_lun,lun
return
end
|
|
|