[Date Index]
[Thread Index]
[Author Index]
Re: Memory leak in StringSplit in Mathematica 7
*To*: mathgroup at smc.vnet.net
*Subject*: [mg97297] Re: [mg97255] Memory leak in StringSplit in Mathematica 7
*From*: Oyvind Tafjord <tafjord at wolfram.com>
*Date*: Tue, 10 Mar 2009 05:35:47 -0500 (EST)
*References*: <200903090606.BAA09399@smc.vnet.net>
Hi Scott,
You are exactly right, there is a small, but very unfortunate memory leak
here affecting any StringSplit call. Will be fixed in next release.
It's not a new bug, by the way, but it's the first time I've heard about it.
Thanks,
Oyvind Tafjord
Wolfram Research
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
>
Prev by Date:
**Re: Wolfram/Alpha**
Next by Date:
**Re: Notebook that auto-executes when opened?**
Previous by thread:
**Memory leak in StringSplit in Mathematica 7**
Next by thread:
**Re: Memory leak in StringSplit in Mathematica 7**
| |