Re: Freeing memory in Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg19546] Re: Freeing memory in Mathematica
- From: "David Bailey" <dave-bailey at freeuk.com>
- Date: Tue, 31 Aug 1999 00:52:31 -0400
- References: <7q9g8i$o43@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
bettina_hansen at writeme.com wrote in message <7q9g8i$o43 at smc.vnet.net>... >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[]] > >Gives: > 836032 > 1906744 > 836352 > Hello, 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: Print[MemoryInUse[]]; list = Table[foo[i], {i, 1, 20000}]; 42; Print[MemoryInUse[]]; list =.; Print[MemoryInUse[]]; David Bailey Salford Software db at salford-software.com