[ncl-talk] delete() is not clearing memory?
Walter Hannah
walter at hannahlab.org
Wed Oct 28 11:22:30 MDT 2015
I'm having lots of "malloc" errors lately, and I realized that when I use
the "delete" function, NCL doesn't free up as much memory as it created!!!
After doing some sleuthing I figured out that the problem happens after I
use the reassingment operator ":=" to reduce a variable to a subset of
itself like this:
X := X(0,:)
I've come up with a stand alone NCL script (see below) that anyone should
be able to run on a linux machine to reproduce the problem. It prints out
the memory usage from the "ps" command.
procedure printMem (msg)
local rss,cmd
begin
cmd = "ps --no-headers -o 'rss' -C ncl"
rss = max(toint(systemfunc(cmd))) / 1024.
print("NCL memory: "+sprintf("%6.2f",rss)+" "+msg)
end
begin
dims = (/10000,100,100/)
print("")
printMem("basline memory")
print("")
;-----------------------------------------------------
;-----------------------------------------------------
X = new( dims ,float)
printMem("X created")
delete(X)
printMem("X deleted")
print("")
;-----------------------------------------------------
;-----------------------------------------------------
X = new( dims ,float)
printMem("X created")
X := X
printMem("X reassigned")
delete(X)
printMem("X deleted")
print("")
;-----------------------------------------------------
;-----------------------------------------------------
end
The output of the script on my linux machine is:
(0)
(0) NCL memory: 74.38 basline memory
(0)
(0) NCL memory: 456.11 X created
(0) NCL memory: 74.66 X deleted
(0)
(0) NCL memory: 456.13 X created
(0) NCL memory: 837.44 X reassigned
(0) NCL memory: 456.14 X deleted
(0)
So, after using doing the reassignment it seems that a copy of the variable
is left in memory and never cleared.
I can work around it for now, but I wanted to ask if anyone knew about
this, and also can it be fixed?
Thanks,
Walter Hannah
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20151028/7e6e265f/attachment.html
More information about the ncl-talk
mailing list