In version 7 I cannot confirm what you report. With my default of $HistoryLength = 3 I see:
d = 2000;
f[x_, y_, d_] = Sum[Subscript[a, i, j]*x^i*y^j, {i, 0, d - 1}, {j, 0, d - i}];
MemoryInUse[]
Clear[f]
MemoryInUse[]
774871544
454831808
With $HistoryLength = 0 as suggested by Ruslan:
774868608
14955736
Michael suggested using Block to set $HistoryLength but this doesn't actually work. Instead his code functions by a different method: it never assigns the output of the Sum to Out[], because that line returns MemoryInUse[]. The same thing can be done with with CompoundExpression:
d = 2000;
f[x_, y_, d_] = Sum[Subscript[a, i, j]*x^i*y^j, {i, 0, d - 1}, {j, 0, d - i}]; 1;
MemoryInUse[]
Clear[f];
MemoryInUse[]
774872048
14957200
The key is:
expr; 1;
Now the value set for Out[] is 1 rather than expr.
You may wonder why expr; assigns anything to Out[] -- this is intended and useful behavior because you often want to suppress the output of a line and reference it in the line below using %. expr; is short for CompoundExpression[expr, Null], which is recognized and handled to set Out[] to the evaluated expr instead of Null.
$HistoryLength=0. Then you'll not use additional memory for saving results of old computations (anything like%1won't work in this case). – Ruslan Aug 17 '13 at 17:16flater at some point in the computation, and after that point, I don't need it anymore. – user565739 Aug 17 '13 at 17:26fwith$HistoryLength=0, it'll still remain defined until youClearit. You just won't be able to access output of any previous computed cells via%n, and "Show More" etc. buttons won't work. – Ruslan Aug 17 '13 at 17:28fwith$HistoryLength=0? It seems to me $HistoryLength is defined in the scope of a notebook or larger? What I mean is that can one change$HistoryLengthseveral times in a notebook? – user565739 Aug 17 '13 at 17:35$HistoryLengthonly is about history, not variables you define. So, you can have any value for$HistoryLength, and you can still work with your variables as usual — only not have access to history of outputs. And yes, if you need, you can change$HistoryLengthat any time. – Ruslan Aug 17 '13 at 17:39