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: [mg85640] Re: Garbage collection and mutable data structures
  • From: David Bailey <dave at Remove_Thisdbailey.co.uk>
  • Date: Sun, 17 Feb 2008 07:16:44 -0500 (EST)
  • References: <fp67h9$5f6$1@smc.vnet.net>

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






  • Prev by Date: Re: rendering problem
  • Next by Date: StyleSheets How-to
  • Previous by thread: Re: Garbage collection and mutable data structures
  • Next by thread: Re: Garbage collection and mutable data structures