RE: Memory leak
- To: mathgroup at smc.vnet.net
- Subject: [mg28038] RE: [mg27868] Memory leak
- From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.de>
- Date: Thu, 29 Mar 2001 03:24:06 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
For my observation, see below: > -----Original Message----- > From: Carl K. Woll [mailto:carlw at u.washington.edu] To: mathgroup at smc.vnet.net > Sent: Thursday, March 22, 2001 10:30 AM > To: mathgroup at smc.vnet.net > Subject: [mg28038] [mg27868] Memory leak > > > > Hi all, > > I have recently come across the following command which leaks memory, > and thought that it might be of interest to the Mathematica > community. > To check for memory leaks in a statement, I run the following > commands: > > Print[{MemoryInUse[],MaxMemoryUsed[]}]; > Do[ statement; > Print[{MemoryInUse[],MaxMemoryUsed[]}], {10}] > > If statement has no memory leak, then each of the print > statements above > should be the same (except for the first couple). For a > simple statement > like 1+1 this is indeed the case. However, when using the > Drop command > with more than one sequence specified, each of the print statements > increases by 32 bytes on my system, which is Mathematica 4.0 > on Windows > NT. For example, > > Print[{MemoryInUse[],MaxMemoryUsed[]}]; > Do[ Drop[{{1,2},{3,4}},-1,1]; > Print[{MemoryInUse[],MaxMemoryUsed[]}], {10}] > > will demonstrate this memory leak. If only one sequence > specification is > given, like Drop[{{1,2},{3,4}},-1] then no memory leak > occurs. Feel free > to comment on whether this is an accurate gauge of a memory leak, and > whether your system also experiences this leak. > > Carl Woll > Physics Dept > U of Washington > Dear Carl, I confirm your test on my machine: In[1]:= {$Version, $VersionNumber, $ReleaseNumber} Out[1]= {"4.0 for Microsoft Windows (April 21, 1999)", 4., 0} In[2]:= Print[{MemoryInUse[], MaxMemoryUsed[]}]; Do[Drop[{{1, 2}, {3, 4}}, -1, 1]; Print[{MemoryInUse[], MaxMemoryUsed[]}], {10}] >From In[2]:= {1137560, 1163512} >From In[2]:= {1138232, 1163512} >From In[2]:= {1138264, 1163512} >From In[2]:= {1138296, 1163512} >From In[2]:= {1138328, 1163512} >From In[2]:= {1138360, 1163512} >From In[2]:= {1138392, 1163512} >From In[2]:= {1138424, 1163512} >From In[2]:= {1138456, 1163512} >From In[2]:= {1138488, 1163512} >From In[2]:= {1138520, 1163512} Equivalent code to Drop[<list>, <seq1>, <seq2>,...] is In[4]:= Fold[Map[Function[x, Drop[x, #2[[1]]]], #1, {#2[[2]]}] & , Array[a, {2, 2, 2, 2}], Transpose[{{-1, 1, -1, 1}, {0, 1, 2, 3}}]] Out[4]= {{{{a[1, 2, 1, 2]}}}} compare to In[5]:= Drop[Array[a, {2, 2, 2, 2}], -1, 1, -1, 1] Out[5]= {{{{a[1, 2, 1, 2]}}}} Now with this we find ... In[6]:= Print[{MemoryInUse[], MaxMemoryUsed[]}]; Do[Fold[Map[Function[x, Drop[x, #2[[1]]]], #1, {#2[[2]]}] & , {{1, 2}, {3, 4}}, {{-1, 0}, {1, 1}}]; Print[{MemoryInUse[], MaxMemoryUsed[]}], {10}] >From In[6]:= {1150352, 1163512} >From In[6]:= {1151240, 1163512} >From In[6]:= {1151240, 1163512} >From In[6]:= {1151240, 1163512} >From In[6]:= {1151240, 1163512} >From In[6]:= {1151240, 1163512} >From In[6]:= {1151240, 1163512} >From In[6]:= {1151240, 1163512} >From In[6]:= {1151240, 1163512} >From In[6]:= {1151240, 1163512} >From In[6]:= {1151240, 1163512} no memory leak! So this in fact seems to be a problem of Wolfram, Inc. As to the accurateness of the test, I think, again Wolfram is to comment on. Yours, Hartmut