Re: [long] Mathematica 5.1 and memory: any garbage collection?
- To: mathgroup at smc.vnet.net
- Subject: [mg59740] Re: [mg59697] [long] Mathematica 5.1 and memory: any garbage collection?
- From: stephen layland <layland at wolfram.com>
- Date: Fri, 19 Aug 2005 04:32:12 -0400 (EDT)
- References: <200508180416.AAA08516@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
and thus spake some.poster at use.net [2005.08.18 @ 00:40]:
> Hi,
Hi Some,
> My problem lies with the fact that memory used at intermediate stage seems
> never be freed, even whith explicit Clear, Remove or any assignment to {} or
> . in whatever order.
Remember that Mathematica keeps a history! That way %% and Out[blah]
always return the appropriate expr. You can tell it not to use a
history by setting $HistoryLength = 0.
> In[6]:=
> (* simple mapped function *)
> res=Map[2*#&,try];
> {MemoryInUse[],MaxMemoryUsed[]}
>
> Out[7]=
> {93949328,103186832} (* Ouch ! So much for a _simple_ test *)
Your res is still hiding out in Out[6] here. Compare this to
something like
In[x]:= res2=2 #/@try; MemoryInUse[]
Clear[res2]; MemoryInUse[]
> In[8]:=
> (* forgetting a large expression doesn't free _any_ memory *)
> try={};
> {MemoryInUse[],MaxMemoryUsed[]}
Cause you're not freeing all the computed results...
The best way to accomplish what you're doing is set $HistoryLength = 0
as I mentioned earlier, use Utilities`CleanSlate` (in the docs) or do
something like hack:
Unprotect[Out];
Clear@Out;
> (* ahem, what _is_ Clear supposed to do? *)
> (* ahem, what _is_ Remove supposed to do? *)
The Help browser will tell you. :)
> In[24]:=
> (* sharing common subexpressions somehow works, slow as hell *)
>
> (* please note: even after removing all values and symbols in all
> possible ways, try and res are _still_ somewhere in memory since
> Share _really_ does something! *)
See Above.
> (* Share should share nothing as we don't have any object stored, safe
> perhaps symbols a..f *)
Wrong assumption.
Happy hacking!
--
/*------------------------------*\
| stephen layland |
| Documentation Programmer |
| http://members.wri.com/layland |
\*------------------------------*/
- References:
- [long] Mathematica 5.1 and memory: any garbage collection?
- From: some.poster@use.net
- [long] Mathematica 5.1 and memory: any garbage collection?