Re: [long] Mathematica 5.1 and memory: any garbage collection?
- To: mathgroup at smc.vnet.net
- Subject: [mg59724] Re: [mg59697] [long] Mathematica 5.1 and memory: any garbage collection?
- From: ggroup at sarj.ca
- Date: Fri, 19 Aug 2005 04:31:46 -0400 (EDT)
- References: <200508180416.AAA08516@smc.vnet.net>
- Reply-to: ggroup at sarj.ca
- Sender: owner-wri-mathgroup at wolfram.com
On Thursday, August 18, 2005 at 00:16 GMT -0400, Some.Poster heard voices say: > My problem lies with the fact that memory used at intermediate stage seems > never be freed, even whith explicit Clear, Remove or any assignment to {} or > . in whatever order. I ran your example and got significantly smaller memory usage (see below). Now I ran this on v5, but still 2x10^6 is *much* smaller than 96x10^6. > How can one recover the memory freed (if some is ever effectively freed)? Is > there _any_ garbage collection in the guts of this gazillion dollars piece > of code? It seems that the issue is that although you are clearing the assignment of a value to a variable, you have not unloaded the data from memory; it is stored in the history. So it seems that one solution is to change the $HistoryLength from Infinity to something smaller. Below I ran your code as written. I then restarted the kernel, and set $HistoryLength to 0. Running your code as written didn't change too dramatically (mind you all my memory usage numbers are far more reasonable than yours), but there is certainly a difference. -------------------------Begin------------------------- In[1]:= $ProductInformation Out[1]= {ProductIDName -> Mathematica, ProductKernelName -> Mathematica 5 Kernel, ProductVersion -> 5.0 for Microsoft Windows (November 18, 2003), ProductVersionNumber -> 5.} In[2]:= MemoryInUse[] Out[2]= 2125192 In[3]:= (*let's create a moderate - size object*) try = Tuples[{a, b, c, d, e, f}, 7]; ByteCount[try] {MemoryInUse[], MaxMemoryUsed[]} Out[4]= 96 Out[5]= {2128352, 2169792} In[6]:= (*simple mapped function*) res = Map[2*# &, try]; {MemoryInUse[], MaxMemoryUsed[]} Out[7]= {2135056, 2169792} In[8]:= (*forgetting a large expression doesn't free _any_ memory*) try = {}; {MemoryInUse[], MaxMemoryUsed[]} Out[9]= {2136784, 2169792} In[10]:= (*no more success this way*) try =.; {MemoryInUse[], MaxMemoryUsed[]} Out[11]= {2138352, 2169792} In[12]:= (*... neither a sweep does*) Clear[try]; {MemoryInUse[], MaxMemoryUsed[]} Out[13]= {2140000, 2169792} In[14]:= (*... nor a complete wash*) Remove[try]; {MemoryInUse[], MaxMemoryUsed[]} Out[15]= {2141600, 2169792} In[16]:= (*freeing the result also seems beyond possible*) res = {}; {MemoryInUse[], MaxMemoryUsed[]} Out[17]= {2143328, 2169792} In[18]:= (*still no luck, dad*) res =.; {MemoryInUse[], MaxMemoryUsed[]} Out[19]= {2141936, 2169792} In[20]:= (*ahem, what _is_ Clear supposed to do?*) Clear[res]; {MemoryInUse[], MaxMemoryUsed[]} Out[21]= {2143192, 2169792} In[22]:= (*ahem, what _is_ Remove supposed to do?*) Remove[res]; {MemoryInUse[], MaxMemoryUsed[]} Out[23]= {2144440, 2169792} In[24]:= Share[] {MemoryInUse[], MaxMemoryUsed[]} Out[24]= 120952 Out[25]= {2024384, 2570200} --------------------------End-------------------------- -------------------------Begin------------------------- In[1]:= $HistoryLength = 0 Out[1]= 0 In[2]:= $ProductInformation Out[2]= {ProductIDName -> Mathematica, ProductKernelName -> Mathematica 5 Kernel, ProductVersion -> 5.0 for Microsoft Windows (November 18, 2003), ProductVersionNumber -> 5.} In[3]:= MemoryInUse[] Out[3]= 2124752 In[4]:= (*let's create a moderate - size object*) try = Tuples[{a, b, c, d, e, f}, 7]; ByteCount[try] {MemoryInUse[], MaxMemoryUsed[]} Out[5]= 96 Out[6]= {2130096, 2169824} In[7]:= (*simple mapped function*) res = Map[2*# &, try]; {MemoryInUse[], MaxMemoryUsed[]} Out[8]= {2130568, 2169824} In[9]:= (*forgetting a large expression doesn't free _any_ memory*) try = {}; {MemoryInUse[], MaxMemoryUsed[]} Out[10]= {2130488, 2169824} In[11]:= (*no more success this way*) try =.; {MemoryInUse[], MaxMemoryUsed[]} Out[12]= {2130488, 2169824} In[13]:= (*... neither a sweep does*) Clear[try]; {MemoryInUse[], MaxMemoryUsed[]} Out[14]= {2130488, 2169824} In[15]:= (*... nor a complete wash*) Remove[try]; {MemoryInUse[], MaxMemoryUsed[]} Out[16]= {2130376, 2169824} In[17]:= (*freeing the result also seems beyond possible*) res = {}; {MemoryInUse[], MaxMemoryUsed[]} Out[18]= {2130104, 2169824} In[19]:= (*still no luck, dad*) res =.; {MemoryInUse[], MaxMemoryUsed[]} Out[20]= {2130104, 2169824} In[21]:= (*ahem, what _is_ Clear supposed to do?*) Clear[res]; {MemoryInUse[], MaxMemoryUsed[]} Out[22]= {2130104, 2169824} In[23]:= (*ahem, what _is_ Remove supposed to do?*) Remove[res]; {MemoryInUse[], MaxMemoryUsed[]} Out[24]= {2130032, 2169824} In[25]:= Share[] {MemoryInUse[], MaxMemoryUsed[]} Out[25]= 115280 Out[26]= {2014464, 2556896} --------------------------End--------------------------
- References:
- [long] Mathematica 5.1 and memory: any garbage collection?
- From: some.poster@use.net
- [long] Mathematica 5.1 and memory: any garbage collection?