<div dir="ltr">I&#39;m having lots of &quot;malloc&quot; errors lately, and I realized that when I use the &quot;delete&quot; function, NCL doesn&#39;t free up as much memory as it created!!!<div><br></div><div>After doing some sleuthing I figured out that the problem happens after I use the reassingment operator &quot;:=&quot; to reduce a variable to a subset of itself like this:</div><div><br></div><div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><font face="monospace, monospace">X := X(0,:)</font></blockquote></div><div><br></div><div>I&#39;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 &quot;ps&quot; command. </div><div><br></div><div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace, monospace">procedure printMem (msg)</font></div><div><div><font face="monospace, monospace">local rss,cmd</font></div><div><font face="monospace, monospace">begin</font></div><div><font face="monospace, monospace">    cmd = &quot;ps --no-headers  -o &#39;rss&#39; -C ncl&quot;</font></div><div><font face="monospace, monospace">    rss = max(toint(systemfunc(cmd))) / 1024.</font></div></div><div><font face="monospace, monospace">    print(&quot;NCL memory:    &quot;+sprintf(&quot;%6.2f&quot;,rss)+&quot;     &quot;+msg)</font></div><div><font face="monospace, monospace">end</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">begin</font></div><div><font face="monospace, monospace">    dims = (/10000,100,100/)</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">    print(&quot;&quot;)</font></div><div><font face="monospace, monospace">    printMem(&quot;basline memory&quot;)</font></div><div><font face="monospace, monospace">    print(&quot;&quot;)</font></div><div><font face="monospace, monospace">    ;-----------------------------------------------------</font></div><div><font face="monospace, monospace">    ;-----------------------------------------------------</font></div><div><font face="monospace, monospace">    X = new( dims ,float)</font></div><div><font face="monospace, monospace">    printMem(&quot;X created&quot;)</font></div><div><font face="monospace, monospace">    delete(X)</font></div><div><font face="monospace, monospace">    printMem(&quot;X deleted&quot;)</font></div><div><font face="monospace, monospace">    print(&quot;&quot;)</font></div><div><font face="monospace, monospace">    ;-----------------------------------------------------</font></div><div><font face="monospace, monospace">    ;-----------------------------------------------------</font></div><div><font face="monospace, monospace">    X = new( dims ,float)</font></div><div><font face="monospace, monospace">    printMem(&quot;X created&quot;)</font></div><div><font face="monospace, monospace">    X := X</font></div><div><font face="monospace, monospace">    printMem(&quot;X reassigned&quot;)</font></div><div><font face="monospace, monospace">    delete(X)</font></div><div><font face="monospace, monospace">    printMem(&quot;X deleted&quot;)</font></div><div><font face="monospace, monospace">    print(&quot;&quot;)</font></div><div><font face="monospace, monospace">    ;-----------------------------------------------------</font></div><div><font face="monospace, monospace">    ;-----------------------------------------------------</font></div><div><font face="monospace, monospace">end </font></div></blockquote></div><div><br></div><div>The output of the script on my linux machine is:</div><div><br></div><div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace, monospace">(0)</font></div><div><font face="monospace, monospace">(0)<span class="" style="white-space:pre">        </span>NCL memory:     74.38     basline memory</font></div><div><font face="monospace, monospace">(0)</font></div><div><font face="monospace, monospace">(0)<span class="" style="white-space:pre">        </span>NCL memory:    456.11     X created</font></div><div><font face="monospace, monospace">(0)<span class="" style="white-space:pre">        </span>NCL memory:     74.66     X deleted</font></div><div><font face="monospace, monospace">(0)</font></div><div><font face="monospace, monospace">(0)<span class="" style="white-space:pre">        </span>NCL memory:    456.13     X created</font></div><div><font face="monospace, monospace">(0)<span class="" style="white-space:pre">        </span>NCL memory:    837.44     X reassigned</font></div><div><font face="monospace, monospace">(0)<span class="" style="white-space:pre">        </span>NCL memory:    456.14     X deleted</font></div><div><font face="monospace, monospace">(0)</font></div></blockquote></div><div><br></div><div>So, after using doing the reassignment it seems that a copy of the variable is left in memory and never cleared.</div><div><br></div><div>I can work around it for now, but I wanted to ask if anyone knew about this, and also can it be fixed?</div><div><br></div><div>Thanks,</div><div>Walter Hannah</div></div>