Re: Memory leak in StringSplit in Mathematica 7
- To: mathgroup at smc.vnet.net
- Subject: [mg97307] Re: [mg97255] Memory leak in StringSplit in Mathematica 7
- From: Curtis Osterhoudt <cfo at lanl.gov>
- Date: Tue, 10 Mar 2009 05:37:37 -0500 (EST)
- Organization: LANL
- References: <200903090606.BAA09399@smc.vnet.net>
- Reply-to: cfo at lanl.gov
Confirmed: the same thing here in V. 7 for linux.
On Monday 09 March 2009 12:06:19 am Scott Morrison 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
>
>
--
==========================================================
Curtis Osterhoudt
cfo at remove_this.lanl.and_this.gov
PGP Key ID: 0x4DCA2A10
Please avoid sending me Word or PowerPoint attachments
See http://www.gnu.org/philosophy/no-word-attachments.html
==========================================================
- References:
- Memory leak in StringSplit in Mathematica 7
- From: Scott Morrison <scott.morrison@gmail.com>
- Memory leak in StringSplit in Mathematica 7