How can i clear values saved by “Function That Remember Values They Have Found” without clearing the definition of the function? I have problems with memory usage.
For example:
In:
f[x_] := f[x] =x^2;
f[0];
f[1];
?f
Out:
Global`f
f[0]=0
f[1]=1
f[x_]:=f[x]=x^2
I want to clear all of the saved values (without specifying the values) and have this
You can also be interested in Leonid Shifrin’s Cache.m package. Citing the home page (emphasis is mine):
This package allows one to create a “copy” of a given function of a
single argument (Downvalue-based or a pure function), with an internal cache of the fixed size . This cache will automatically store results
of the most recent function calls, and use the stored values rather
than recompute the r.h.s. in case if the function is called again on
the same argument. This may speed-up computations considerably in
cases when a function is both computationally intensive and is
frequently called on the same values of the argument.