Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1999

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

Search the Archive

Re: Freeing memory in Mathematica

  • To: mathgroup at
  • Subject: [mg19546] Re: Freeing memory in Mathematica
  • From: "David Bailey" <dave-bailey at>
  • Date: Tue, 31 Aug 1999 00:52:31 -0400
  • References: <7q9g8i$>
  • Sender: owner-wri-mathgroup at

bettina_hansen at wrote in message <7q9g8i$o43 at>...
>Hallo everyone.
>I was trying to make a Mathematica program which make some calculations
>on several long (and very large) lists. However, after the calculation
>of each list, the list is no longer needed. So I tried to delete it
>using listname=. However it seems that this is not working in the sense
>that it is still present in memory. Finally I found out how to free the
>memory, see the following. Can anyone tell me how to do this more
>'nice'? (i.e. without the use of the NoUse variable?)
>The program is written in the file 'test.m'. The first program shows how
>I want it to be, but as is seen this does not work.
>  Print[MemoryInUse[]]
>  list=Table[Sqrt[i],{i,1,20000}];
>  Print[MemoryInUse[]]
>  list=.
>  Print[MemoryInUse[]]
>Gives, when 'executing' <<Test.m :
>  836032
>  1906640
>  1906640
>I.e. the list is not deleted from memory. The second program, however,
>works fine:
>  Print[MemoryInUse[]]
>  list=Table[Sqrt[i],{i,1,20000}]; NoUse=1;
>  Print[MemoryInUse[]]
>  list=.
>  Print[MemoryInUse[]]
>  836032
>  1906744
>  836352


My first thought was that as printed you had missed out some semicolons, so
maybe things were not
getting executed in the right order. However, adding semicolons made no
difference! My second thought was that Mathematica was caching some
information about all those square roots (does cached info count in the
MemoryInUse figure?), so I replaced Sqrt by foo - still no change. It turns
out that you can replace the assignment of NoUse by anything with a non-null
value - e.g. the number 42. It also seems that even when the memory in use
does not go down, if you test it afterwards it HAS gone back down - so my
guess is that Mathematica is holding on to the value as a possible return
value from the compound expression, even though it should know the answer is
Null. This is my simplified working case:

list = Table[foo[i], {i, 1, 20000}];
list =.;

David Bailey
Salford Software
db at

  • Prev by Date: SymbolShape
  • Next by Date: Re: Manipulation of equations and inequalities in "high-school style"
  • Previous by thread: Re: Freeing memory in Mathematica
  • Next by thread: Manipulation of equations and inequalities in "high-school style"