Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: Memory operations

  • To: mathgroup at smc.vnet.net
  • Subject: [mg64929] Re: Memory operations
  • From: Maxim <m.r at inbox.ru>
  • Date: Wed, 8 Mar 2006 00:59:40 -0500 (EST)
  • References: <dujr2t$8pr$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On Tue, 7 Mar 2006 11:33:49 +0000 (UTC), <sir_puding at tut.by> wrote:

> Hi.
>
> Can anyone tell me how to free memory in Mathematica.
>
> I have some list operations in cycle (really long cycle).
> Smth. like
>
> -----------------------
> ar={};
> For[i=0,++i<10000000000,
> ar=Append[ar,{bla bla bla}];
> ]
> -----------------------
> How can i free memory allocated for ar  when cycle is completed --- i
> have terrible memory leakage (several megs in minute), cause when I use  
> Clear or Remove ar does
> not point to any address, but the result of previous calculations is
> still in memory. I could not find any operation like free() in C.
>
>
> Tnx.
>

This is due to a strange glitch that appears when For returns the value to  
the top level:

In[1]:= out1 = For[i = 1, i <= 5, i++, 0]

In[2]:= {out1, %}

Out[2]= {Null, Null}

In[3]:= out2 = For[i = 1, i <= 5, i++;, 0]

In[4]:= {out2, %}

Out[4]= {Null, 5}

The result of i++ is stored in DownValues[Out]. So in your case even after  
Clear[ar] the memory taken by the structure is not deallocated because  
there is still a reference to it from DownValues[Out]. Either set  
$HistoryLength = 0 or rewrite your For loop in a different way.

Maxim Rytin
m.r at inbox.ru


  • Prev by Date: Mathematica and Education
  • Next by Date: Re: Bizarre results with TreePlot
  • Previous by thread: Re: Re: Memory operations
  • Next by thread: Bizarre results with TreePlot