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?