MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Memory Leak

  • To: mathgroup at smc.vnet.net
  • Subject: [mg66878] Re: Memory Leak
  • From: ab_def at prontomail.com
  • Date: Fri, 2 Jun 2006 04:09:06 -0400 (EDT)
  • References: <e5jrth$e09$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Lawrence Weintraub wrote:
> I've looked through the many comments on memory leaks and cannot solve my
> montonically increasing memory usage.  Setting $HistoryLength=0 doesn't
> help.  Using ClearCache[] doesn't do much either.  If anyone could help
> me, I'd be very grateful.  My (simplified) code is:
>
> $HistoryLength=0;
>
> memEater[smin_?Positive, smax_, sigma_?Positive, fluxes_] :=
>      Module[{s, snew, snoise, result, noisevec, bigvec, ds = 0.01, likes,
>          likeFunc,t},
>       snMin = -40.*sigma;
>       s = Range[Min[fluxes], Max[fluxes], ds];
>       snoise = Range[snMin, -snMin, ds];
>       noisevec = Exp[-(Range[snMin, -snMin, ds])^2];
>       bigvec = ListConvolve[noisevec, Abs[s], {1, -1}, 0.0];
>       snew = Range[s[[1]] + snoise[[1]],s[[-1]] + snoise[[-1]],ds];
>       s =.;
>       snoise =.; noisevec =.;
>       t = Transpose[{snew, bigvec}];
>       likeFunc = Interpolation[t];
>       t =.; snew =.; bigvec =.;
>       likes = likeFunc[#] & /@ fluxes;
>       Clear["likeFunc$*"];
>       result = If[Min[likes] < 0, -10.*Length[fluxes],
>                   Plus @@ (Log[#] & /@ likes)]; likes =.;
>       result];
>
> When I run this:
>
> ct = 0; mem0 = MemoryInUse[];
> fluxes = Table[Random[]*35. - 5., {i, 1000}];
> Do[mem = MemoryInUse[];
> res = memEater[.2, 30., 0.3, fluxes];
> Print[MemoryInUse[] - mem0];
> Developer`ClearCache[];
> Print[MemoryInUse[] - mem0];,{10}];
>
> From In[82]:=
> 46080
>
> From In[82]:=
> 46080
>
> From In[82]:=
> 93320
>
> From In[82]:=
> 93320
>
> From In[82]:=
> 140560
>
> From In[82]:=
> 140560
>
> From In[82]:=
> 187800
>
> From In[82]:=
> 187800
>
> From In[82]:=
> 235040
>
> From In[82]:=
> 235040
>
> From In[82]:=
> 282280
>
> From In[82]:=
> 282280
>
> From In[82]:=
> 329520
>
> From In[82]:=
> 329520
>
> From In[82]:=
> 376760
>
> From In[82]:=
> 376760
>
> From In[82]:=
> 424000
>
> From In[82]:=
> 424000
>
> From In[82]:=
> 471240
>
> From In[82]:=
> 471240
>
>
>
> Larry Weintraub
> Astrophysics
> California Institute of Technology
> 1200 E California Blvd
> MC 105-24
> Pasadena, CA 91125
>
> lcw at astro.caltech.edu
> 626-395-4051

The memory leak is caused by Interpolation:

tmp = MaxMemoryUsed[];
ListPlot[Table[
    Interpolation[Array[N@ {#, 2*#}&, 5000]]; MaxMemoryUsed[],
    {100}] - tmp]

FindFit gives an estimate of 40000 bytes per iteration, so it looks
like Interpolation leaves behind a list of 5000 reals.
ListInterpolation doesn't seem to have this problem, so just replace
likeFunc = Interpolation[t] with likeFunc = ListInterpolation[bigvec,
{snew}].

Maxim Rytin
m.r at inbox.ru


  • Prev by Date: RE: Installing AddOn
  • Next by Date: Re: Problem with the Sum Function -- Using a Benford Distribution
  • Previous by thread: Re: A conditional random number generation problem (please help me!)
  • Next by thread: tensors, matrices, and rotation