Re: Memory Management
- To: mathgroup at smc.vnet.net
- Subject: [mg13648] Re: [mg13623] Memory Management
- From: David Withoff <withoff>
- Date: Fri, 7 Aug 1998 10:13:04 -0500 (CDT)
- Sender: owner-wri-mathgroup at wolfram.com
> Has any body an idea about Memory Management in Mathematica?? > > For example what happend with the memory allocated by an expression when > I clear this expression? Clear[exp] This is what I do: > > exp=Read[stmp, nomfich]; > MemoryInUse[] ---> 867664 > Clear[exp] > MemoryInUse[] ---> 868584 If the memory associated with the value of exp isn't recovered, this means that the value must still be in use. In your example it is likely that the value of exp is being used in a value of Out. If so, you can recover that memory by clearing Out or by unsetting the appropriate value of Out, as in: In[2]:= exp=Read["data"]; In[3]:= MemoryInUse[] Out[3]= 922208 In[4]:= Clear[exp] In[5]:= MemoryInUse[] Out[5]= 923008 In[6]:= Unprotect[Out]; Out[2]=.; Protect[Out] ; In[7]:= MemoryInUse[] Out[7]= 723876 If there are still other references to the value of exp, they would need to be cleared as well. If you want to locate all of the references to an expression, and aren't able to do so by some other means, it is always possible to track down references using methods such as In[1]:= exp=Read["data"]; In[2]:= FindReferences[p_]:= Scan[Function[{e},If[!MemberQ[Attributes[e], ReadProtected], If[!FreeQ[ToExpression[e,InputForm,#]& /@ {OwnValues, DownValues, SubValues, UpValues},p], Print["reference found from symbol ", e]] ]], Names["*"]] In[3]:= FindReferences[exp] reference found from symbol exp reference found from symbol Out which reports all of the symbols that include references to the expression. This sort of thing is rarely necessary, though. In most cases it is not difficult to find references just by looking at a program, or to set up a program so that unwanted references aren't introduced in the first place. Dave Withoff Wolfram Research