[ncl-talk] delete() is not clearing memory?

Mary Haley haley at ucar.edu
Thu Oct 29 12:23:17 MDT 2015


Walter,

Thanks for sending a little script that shows the issue.  I'm not seeing
the same large difference of results as you, but I do see some slight
increase.  If I run the script multiple times, I get very different
results, so I'm not sure exactly what kind of memory usage is being
reported by the "ps" command you provided.

What version of NCL are you using?

--Mary


On Wed, Oct 28, 2015 at 11:22 AM, Walter Hannah <walter at hannahlab.org>
wrote:

> 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
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20151029/d603cddf/attachment.html 


More information about the ncl-talk mailing list