Re: Memory leak in StringSplit in Mathematica 7
- To: mathgroup at smc.vnet.net
- Subject: [mg97298] Re: Memory leak in StringSplit in Mathematica 7
- From: Scott Morrison <scott.morrison at gmail.com>
- Date: Tue, 10 Mar 2009 05:35:59 -0500 (EST)
- References: <gp2bkh$95g$1@smc.vnet.net>
I just got a reply from Wolfram acknowledging this bug; they say it will be fixed in the next release. On Mar 8, 11:06 pm, Scott Morrison <scott.morri... at gmail.com> wrote: > I'm on OSX 10.5, running Mathematica 7. There's apparently a memory leak = in > StringSplit -- 16 bytes get used up every call. See below for a "by > hand" implementation of StringSplit, and two test runs showing the > difference. > > The problem had caused big problems; a long run of one of my programs > was mysteriously starting to page memory unnecessarily, and switching > to the "by hand" implementation fixes the problem. > > In[135]:= StringSplitWithoutMemoryLeak[S_,V_]:=StringTake[S,#]&/ > @Partition[{1}~Join~Flatten[#+{-1,1}&/@StringPosition[S,V]]~Join~{-1}, > 2] > In[145]:= StringSplitWithoutMemoryLeak["12341234","2"]==StringSplit > ["12341234","2"] > Out[145]= True > In[137]:= randomString:=StringJoin@@RandomChoice[{"0,","1","2"},10] > In[143]:= Do[Print["Memory in use: ",MemoryInUse[]];Print["Time for > 100000 StringSplits: ",AbsoluteTiming[Do[StringSplit[randomString,"0"], > {100000}]][[1]]],{4}] > During evaluation of In[143]:= Memory in use: 130297096 > During evaluation of In[143]:= Time for 100000 StringSplits: 1.312322 > During evaluation of In[143]:= Memory in use: 131897496 > During evaluation of In[143]:= Time for 100000 StringSplits: 1.345231 > During evaluation of In[143]:= Memory in use: 133497496 > During evaluation of In[143]:= Time for 100000 StringSplits: 1.314813 > During evaluation of In[143]:= Memory in use: 135097496 > During evaluation of In[143]:= Time for 100000 StringSplits: 1.403105 > In[144]:= Do[Print["Memory in use: ",MemoryInUse[]];Print["Time for > 100000 StringSplits: ",AbsoluteTiming[Do[StringSplitWithoutMemoryLeak > [randomString,"0"],{100000}]][[1]]],{4}] > During evaluation of In[144]:= Memory in use: 136701120 > During evaluation of In[144]:= Time for 100000 StringSplits: 3.918605 > During evaluation of In[144]:= Memory in use: 136701480 > During evaluation of In[144]:= Time for 100000 StringSplits: 3.948706 > During evaluation of In[144]:= Memory in use: 136701480 > During evaluation of In[144]:= Time for 100000 StringSplits: 3.952957 > During evaluation of In[144]:= Memory in use: 136701480 > During evaluation of In[144]:= Time for 100000 StringSplits: 3.916070