Context
I run long Mathematica sessions; sometimes I have Output up to Out[3000+]. Hence I would like to be able to clear out some previous outputs which do use lots of memory.
Attempt
I am aware of clearing some outputs via unprotecting Out
as follows
In[1]:= MemoryInUse[]/10^9.
Out[1]= 0.0179439
In[2]:= a = Table[1, {10^8}];
In[3]:= MemoryInUse[]/10^9.
Out[3]= 0.419424
In[4]:= Unprotect[Out];
In[5]:= Out[2] =.
In[6]:= Protect[Out];
In[7]:= MemoryInUse[]/10^9.
Out[7]= 0.0297147
My problem is if I have 3000+ outputs, which one are using a lot of memory so I can decide if it is safe to clear them.
Question
What I am after is a way of finding out which amongst the previous Out
are using most of the memory?
I would like to have a function, say MemoryHog[n]
which would return a list of numbers corresponding to the n
th sorted Outputs using most memory.