Mathematica 9 is now available
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: [mg85678] Re: Garbage collection and mutable data structures
  • From: massyah at gmail.com
  • Date: Tue, 19 Feb 2008 01:54:59 -0500 (EST)
  • References: <200802160833.DAA05441@smc.vnet.net> <fp99hk$1i0$1@smc.vnet.net>

Thanks for all the answers!

> It looks like if you let a temporary escape from the Module[] (i.e. you
> create references to it outside the Module[] by returning it), then it
> won't be cleaned up.

Yes, this is exactly my problem, as I want a module to create some
references, while being able to free them automatically afterwards.


> The temporary 'c' variables are still in use because Up Values are
> attached to them!

Yes, but should'nt they be freed anyway, regardless of the info
attached to them ? My point of view (coming from other languages with
garbage collection / reference couting) is that any variable with a
ref count of 0 should be freed. Here, all the "c" returned by the
module should have a ref count of 0 since I can't access them (except
by listing all the variables in the kernel). And the same problem
arise if I use the dual (downvalues attached to "c")


> Why not describe what it is you are trying to do.

Because I thought it was not significant for this problem.

Basically, I want to describe mutable data structures with pointers
(i.e. any kind of graph). Let's say I want to encode the chained list
   c0 -> c1 -> c2
where (for a memory-wise approach) the only way to access to c2 is to
traverse the structure by using a "NextCell" pointer. I thought of
using upvalues in this scheme:
* c1 == NextCell[c0]
* c2 == NextCell[NextCell[c0]]
etc.

In e.g. python, whenever I "release" c0 by assigning it a new value,
the whole graph is discarded (since I don't have any way to access
c1,c2 etc.). I want to replicate this in Mathematica, without
explicitly having to free all the graph via a traversal.



> try
> Information /@ Names["c$*"]
>
> and find out where the reference to c$* is keept.

All the references to c are kept in the global module, with a
downvalue attached to them.

Global`c$100
Attributes[c$100]={Temporary}
c$100[CellVal]=26




> I don' think so, have you accounted for the memory used to hold the =A0
> values of CellVac[c]?


Since I'm using upvalues, all the info is kept in the "c"s and CellVal
stays empty:

?CellVal
Global`CellVal


Thanks again for your answers,
Hayssam.


  • Prev by Date: Re: [functional approach should give] an even faster way to normalize
  • Next by Date: Re: Mathematica 6 over ssh tunnel
  • Previous by thread: Re: Garbage collection and mutable data structures
  • Next by thread: Re: Garbage collection and mutable data structuresDavid Bailey,http://www.dbaileyconsultancy.co.uk