MathGroup Archive 2003

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

Search the Archive

Re: What Happens to Garbage in Mathematica?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg44031] Re: What Happens to Garbage in Mathematica?
  • From: Olaf Rogalsky <olaf.rogalsky at theorie1.physik.uni-erlangen.de>
  • Date: Sat, 18 Oct 2003 03:12:27 -0400 (EDT)
  • References: <bm84s2$fug$1@smc.vnet.net> <bmg0nf$e9t$1@smc.vnet.net> <bmj2j5$pqs$1@smc.vnet.net> <bmlkj3$6ng$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

nafod40 wrote:
> I'll be curious to hear an authoritative answer. My experience is
> Mathematica only garbage collects when you hold a gun to its head.

I am not authoritative, but may be the Mathematica Book 5.0 
(Chap. 2.14.4) is:

<quote>
Mathematica is careful about the way it uses memory. Every time an 
intermediate expression you have generated is no longer needed, 
Mathematica immediately reclaims the memory allocated to it. This 
means that at any point in a session, Mathematica stores only those
expressions that are actually needed; it does not keep unnecessary
objects which have to be "garbage collected" later. 
</quote>

As mentioned in my previous post, this means to me, that Mathematica
does no garbage collegection at all, but reference counts all objects.

> You
> can fire up an interative routine that repeatedly overwrites an existing
> variable's values, and watch the memory that the kernel uses climb and
> climb and climb. This after exhausting all of the memory tricks
> advocated, such as using a short history, using share, and so on.

intermediate references to your variable. In the following example,
as you can see, the memory usage is constant!

<code>
In[1]:=  i = 0;
         Do[
           If[Mod[i, 10000] == 0, Print[MemoryInUse[ ]]];
           i = i + 1,
           {100000}]
2313304
2313304
2313304
2313304
2313304
2313304
2313304
2313304
2313304
2313304
</code>

Olaf Rogalsky



-- 
+-------------------------------------------------------------------+
I Dr. rer. nat. Olaf Rogalsky     Institut fuer Theoretische Physik I
I                                 Universitaet Erlangen-Nuernberg   I
I Tel.: 09131 8528440             Staudtstr. 7 B3                   I
I Fax.: 09131 8528444             D-91058 Erlangen                  I
| rogalsky at theorie1.physik.uni-erlangen.de                          I
+-------------------------------------------------------------------+


  • Prev by Date: RE: Bug in ReplaceAll and ReplaceRepeated?
  • Next by Date: Re: What Happens to Garbage in Mathematica?
  • Previous by thread: Re: What Happens to Garbage in Mathematica?
  • Next by thread: Re: What Happens to Garbage in Mathematica?