Message Boards Message Boards

0
|
5261 Views
|
6 Replies
|
0 Total Likes
View groups...
Share
Share this post:

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
POSTED BY: Xiaoxu Zhong
6 Replies
Posted 9 years ago

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

POSTED BY: David Keith

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

POSTED BY: Ilian Gachevski

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

POSTED BY: Xiaoxu Zhong

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

POSTED BY: Xiaoxu Zhong

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.

POSTED BY: Ilian Gachevski

Thanks. The problem solves as you said.

POSTED BY: Xiaoxu Zhong
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract