Free Memory

I use iterative method in computation. But function “Clear[ ]” or “ClearAll[ ]” can not free all memory, Which function can do this?

For example:
code:

y = x+x^2;
Print["MemoryInUse is: ",MemoryInUse[]];
b = Integrate[y, x];
ClearAll[b];
Print["MemoryInUse is: ",MemoryInUse[]];

result:

MemoryInUse is: 20201752
MemoryInUse is: 20514544

Try evaluating Share[] after clearing. See Share in the help system.

$HistoryLength = 0 and ClearSystemCache[] may also be useful.

Thank you very much! But I run the code:
y = x + x^2; Print["MemoryInUse is: ", MemoryInUse[] ]; b=Integrate[y,x]; ClearAll[b]; share[]; Print["MemoryInUse is: ", MemoryInUse[] ];
The result is: MemoryInUse is: 20202136 MemoryInUse is: 20516608

Thank you very much! But I run the code: $HistoryLength = 0; y = x + x^2; Print["MemoryInUse is: ", MemoryInUse[] ]; b=Integrate[y,x]; ClearAll[b]; ClearSystemCache[]; Print["MemoryInUse is: ", MemoryInUse[] ]; The result is: MemoryInUse is: 20200432 MemoryInUse is: 20490656

Note that the first time you run a number of Integrate code definitions are being loaded on demand, which accounts for the increase in memory usage.

On subsequent evaluations you should see only a few, if any, bytes difference.

Thanks. The problem solves as you said.