MathGroup Archive 2008

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

Search the Archive

Re: Garbage collection and mutable data structures


On Feb 16, 2008, at 3:33 AM, 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 ?

I don' think so, have you accounted for the memory used to hold the  
values of CellVac[c]?  I did run into a problem with v6 in that a  
large array I was allocating inside a Module was not being freed in  
certain circumstances but that code followed a different pattern than  
yours.  The problem was resolved by explicitly releasing the variable  
in the Module.

Regards,

Sseziwa


  • Prev by Date: Re: Numerical Evaluation
  • Next by Date: [functional approach should give] an even faster way to normalize a
  • Previous by thread: Garbage collection and mutable data structures
  • Next by thread: Re: Garbage collection and mutable data structures