Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 12 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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