Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Garbage collection and mutable data structures

  • To: mathgroup at smc.vnet.net
  • Subject: [mg85659] Re: Garbage collection and mutable data structures
  • From: David Bailey <dave at Remove_Thisdbailey.co.uk>
  • Date: Tue, 19 Feb 2008 01:45:11 -0500 (EST)
  • References: <fp67h9$5f6$1@smc.vnet.net> <fp98kk$u2$1@smc.vnet.net>

David Bailey wrote:
> massyah at gmail.com wrote:
>> Hi MathGroup,
>>
>> This snippet of code is giving me headaches:
>>
>> -----
>> $HistoryLength = 0;
>> NewCell[i_] := Module[{c}, CellVal[c] ^= i; c]
>> MemoryInUse[]
>> NewCell /@ Range[10^5];
>> MemoryInUse[]
>> -----
>>
>> It occurred while trying to build mutable data structures by using
>> upvalues. I can't understand why the temporary variable c is not freed
>> since I don't keep any reference to it.
>> Have I missed something in the reference counting scheme ?
>>
>>
>> Thanks in advance,
>> Hayssam.
>>
> 
> The temporary 'c' variables are still in use because Up Values are 
> attached to them!
> 
> In[1]:= $HistoryLength=0;
> NewCell[i_]:=Module[{c},CellVal[c]^=i;c]
> MemoryInUse[]
> NewCell/@Range[10];
> MemoryInUse[]
> Out[3]= 8977568
> Out[5]= 9012224
> 
> In[7]:= ?c$*
> Global`
> c$	c$940	c$942	c$944	c$946	c$948
> c$939	c$941	c$943	c$945	c$947	
> 
> 
> 
> 
> In[8]:= ?c$943
> Global`c$943
> Attributes[c$943]={Temporary}
> 
> CellVal[c$943]^=5
> 
> Why not describe what it is you are trying to do.
> 
> David Bailey
> http://www.dbaileyconsultancy.co.uk
> 
> 
> 
> 
> 
Just to clarify a bit - reference counting can't collect circular 
structures, and I suspect that CellVal references c$943 which references 
CellVal.

David Bailey
http://www.dbaileyconsultancy.co.uk


  • Prev by Date: RE: Helpfile-like action in ordinary notebook
  • Next by Date: Probable bug: EvaluationMonitor with NIntegrate, "ExtrapolatingOscillatory",
  • Previous by thread: Re: Garbage collection and mutable data structures
  • Next by thread: rendering problem