Re: Garbage collection and mutable data structures
- To: mathgroup at smc.vnet.net
- Subject: [mg85655] Re: [mg85638] Garbage collection and mutable data structures
- From: Sseziwa Mukasa <mukasa at jeol.com>
- Date: Sun, 17 Feb 2008 07:24:32 -0500 (EST)
- References: <200802160833.DAA05441@smc.vnet.net>
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
- References:
- Garbage collection and mutable data structures
- From: massyah@gmail.com
- Garbage collection and mutable data structures