MathGroup Archive 2005

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

Search the Archive

Re: Re: How to free memory?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg59864] Re: [mg59793] Re: How to free memory?
  • From: Igor Antonio <igora at wolf-ram.com>
  • Date: Wed, 24 Aug 2005 06:30:54 -0400 (EDT)
  • Organization: Wolfram Research, Inc.
  • References: <de46jr$r62$1@smc.vnet.net> <de6m36$chm$1@smc.vnet.net> <200508210751.DAA26589@smc.vnet.net>
  • Reply-to: igora at wolf-ram.com
  • Sender: owner-wri-mathgroup at wolfram.com

David Bailey wrote:
> OK, Permit me to extract my foot from my mouth!
> 
> Of course, Out holds the various outputs even if they were terminated by 
> a semicolon - so the 'memory leak' is totally explained. A loop such as
> 
> k = 0; While[True,  k++;  s = Table[i, {i, 1, 10^7}];  Print["Iteration 
> ", k]  ]
> 
> leaks no memory.
> 
> David Bailey http://www.dbaileyconsultancy.co.uk

I was about to hit the send button with a reply to your previous post, 
then I saw this post. :-)

Anyway, I figured I can still share the answer, which contains a simple 
test that might be nice for other users to see.

Cheers,

Igor
----------------------------------------------------------------------

Sure there is significant data stored in the Out[]'s.  The semicolon 
only suppresses the output.  The expression is still created.

Assuming $HistoryLength = default value:

In[10]:=
Quit[]

In[1]:=
MemoryInUse[]

Out[1]=
4071848

In[2]:=
s = Table[i, {i, 1, 10^7}];

In[3]:=
MemoryInUse[]

Out[3]=
44049288

In[4]:=
s = Table[i, {i, 1, 10^7}];

In[5]:=
MemoryInUse[]

Out[5]=
84051304

In[7]:=
ByteCount[Out[2]]

Out[7]=
40000056

In[8]:=
ByteCount[Out[4]]

Out[8]=
40000056
---------------------------------------------------------------
Now, let's set $HistoryLength = 3 (just high enough to keep on value of 
"s").  Now, Out[5]and Out[7] are roughly the same since the value of 
Out[3] is gone.

In[7]:=
Quit[]

In[1]:=
$HistoryLength = 3

Out[1]=
3

In[2]:=
MemoryInUse[]

Out[2]=
4046456

In[3]:=
s = Table[i, {i, 1, 10^7}];

In[4]:=
MemoryInUse[]

Out[4]=
44049544

In[5]:=
s = Table[i, {i, 1, 10^7}];

In[6]:=
MemoryInUse[]

Out[6]=
84050040

In[7]:=
s = Table[i, {i, 1, 10^7}];

In[8]:=
MemoryInUse[]

Out[8]=
84050232

-- 


Igor C. Antonio
Wolfram Research, Inc.
http://www.wolfram.com

To email me personally, remove the dash.


  • Prev by Date: Re: List Replace Problems
  • Next by Date: Re: List Replace Problems
  • Previous by thread: Re: How to free memory?
  • Next by thread: Re: How to free memory?