8
$\begingroup$

This question already has an answer here:

When I'm creating large lists with Table I see the memory footprint increasing.

MemoryInUse[]/1024.
(* Out-> 16992.4 *)

data = Table[x, {x, 0, 10000}, {y, 10000}];    
MemoryInUse[]/1024.
(* Out-> 408372. *)

I would expect that when I generate the same command data = Table[...] just as above the memory would not increase but in fact it just allocates a new block of memory.

data = Table[x, {x, 0, 10000}, {y, 10000}];   
MemoryInUse[]/1024.
(* Out -> 799041. *)

Why is that? Even when I do:

Clear[data];
MemoryInUse[]/1024.
(* Out-> 799044. *)

Is this expected behaviour or am I missing something? I can't seem to find a function that clears the memory.

I'm using Mathematica 8.0.4.0 on Windows 7

$\endgroup$

marked as duplicate by Kuba Dec 10 '18 at 7:49

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

14
$\begingroup$

Have you tried setting $HistoryLength to zero:

$HistoryLength=0;

The memory is not freed, because the previous data is still available by Out[nn] or %nn.

Note that if you do this, using %, %%, %n etc., which some people use in example code will not work. And when a large data set is shown the "Show More" and "Show Less" buttons do not work. You can bypass both problems by setting $HistoryLength to 1 while still conserving a lot of memory.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.