4
$\begingroup$

Bug introduced in 10.0.0 and fixed in 10.0.2


Consider the following code.

Clear[f, g] f[x_, list_] := Function[i, If[MemberQ[list, {i, i}], N[x], 0]]; g[x_, list_] := Function[i, N[x]]; v = f[2, {{1, 1}}]; w = g[2, {{1, 1}}]; 

Then, running the code below reveals that v consumes much more memory than w, despite their similar definitions.

MemoryInUse[] v[1] & /@ Range[100000]; MemoryInUse[] w[1] & /@ Range[100000]; MemoryInUse[] 

Why is this so?

$\endgroup$
1
  • $\begingroup$ In version 10.0.2 I get the output 85137712, 87550608, 88353400. I shall mark this accordingly. $\endgroup$ Commented Apr 7, 2015 at 15:09

1 Answer 1

5
$\begingroup$

This appears to have been a bug that was present in version 10.0, but has been fixed in version 10.1.

I can reproduce the behaviour using Mathematica version 10.0.1, but the leak does not occur in versions 7.0.1, 8.0.1, 9.0.1, or 10.1 (all on Win7 64-bit). I initially set $HistoryLength = 0 to remove saved results from consideration.

I speculate that MemberQ in v10.0 is creating an intermediate structure for searching, and that structure is not being released after use. If I change the code to use !FreeQ instead, then the leak persists. The leak disappears if I define my own simplistic memberQ function:

memberQ[list_, v_] := Scan[If[#===v, Return[True]]&, list] /. Null -> False 

Whatever structure MemberQ is building, it is not reclaimed when I call ClearSystemCache.

$\endgroup$
3
  • 1
    $\begingroup$ There was indeed a memory leak in MemberQ and FreeQ, introduced in 10.0.0 and fixed in 10.0.2 (and also 10.1.0). $\endgroup$ Commented Apr 7, 2015 at 15:24
  • 4
    $\begingroup$ @StefanR In general, is the list of bug fixes available anywhere? $\endgroup$ Commented Apr 7, 2015 at 15:34
  • $\begingroup$ @anon No, I'm afraid they aren't. $\endgroup$ Commented Apr 7, 2015 at 17:34

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.