memModule[] :=
Module[{data, memBefore, mu},
mu := Grid[{{"Memory in use: ", MemoryInUse[]/(2^30.), "GB"}}];
memBefore = mu;
data = RandomReal[1, {300000, 20}];
DynamicModule[{d1},
d1 := data[[1]];
Panel[Grid[{{memBefore}, {mu}}]]
, UnsavedVariables -> {dl}
]
];
memModule[]
memModule[]
memModule[]
Your support will be appreciated,
--
Ariel Sepulveda, Ph.D.
__________________________
President, Pronto Analytics Inc.
Tel. 787.354.6947
ariel.s...@prontoanalytics.com
http://www.prontoanalytics.com
I've encountered this problem before. The problem is that the variables
created by Module are not de-allocated as long as there is a reference to
them from any global symbol or construct outside the original Module's
scope. In your case, the panels wrapped in DynamicModule are such
constructs.
One possible solution is to create explicit deallocating functions, for
example as follows:
Clear[memModule, getHeap, clearHeap];
Module[{heap = {}},
getHeap[] := heap;
clearHeap[] :=
While[heap =!= {},
Remove @@ Last[heap];
heap = Most@heap];
memModule[] :=
Module[{data, memBefore, mu},
mu := Grid[{{"Memory in use: ", MemoryInUse[]/(2^30.), "GB"}}];
memBefore = mu;
data = RandomReal[1, {300000, 20}];
heap = Append[heap, Hold[data, memBefore, mu]];
DynamicModule[{d1}, d1 := data[[1]];
Panel[Grid[{{memBefore}, {mu}}]], UnsavedVariables -> {d1}]]
];
I introduced getHeap for illustrational purposes - the real work is done by
clearHeap. Now observe:
In[3]:=
memModule[]
Out[3]= (*Skipped *)
In[4]:= getHeap[]
Out[4]= {Hold[data$510, memBefore$510, mu$510]}
In[5]:= MemoryInUse[]
Out[5]= 58864208
In[6]:= clearHeap[]
In[7]:= MemoryInUse[]
Out[7]= 10864784
In[8]:= memModule[]
memModule[]
Out[8]= Skipped
Out[9]= Skipped
In[10]:= getHeap[]
Out[10]= {Hold[data$526, memBefore$526, mu$526],
Hold[data$531, memBefore$531, mu$531]}
In[11]:= MemoryInUse[]
Out[11]= 106863840
In[12]:= clearHeap[]
In[13]:= MemoryInUse[]
Out[13]= 10871688
This is one of the instances of the more general garbage collection issues
associated with Module-generated variables used in "non-standard" ways.
Please see my third post in this thread:
and there also references to a couple of more threads with a discussion of
this topic.
Hope this helps.
Regards,
Leonid