1

Actually relate my this post.But I don't want to clear all memory took up by Mathematica.

memory:=Row[{"Memory Used:",MemoryInUse[]/1024^2.," MB"}]
memory
(* Memory Used:109.582 MB *)

a=RandomInteger[1,{10^8}];
memory
(* Memory Used:871.666 MB *)

b=RandomInteger[1,{10^8}];
memory
(* Memory Used:1634.61 MB *)

I want to clear the variable a and release the space took up by variable a but keep the b. Is possible?

yode
  • 26,686
  • 4
  • 62
  • 167

1 Answers1

4

Using $HistoryLength = 0 and Clear[a] works for me:

$HistoryLength = 0;
memory:=Row[{"Memory Used:",MemoryInUse[]/1024^2.," MB"}]
memory

a=RandomInteger[1,{10^8}];
memory

b=RandomInteger[1,{10^8}];
memory

Clear[a];
memory

Memory Used:227.932 MB

Memory Used:990.87 MB

Memory Used:1753.81 MB

Memory Used:990.868 MB

Carl Woll
  • 130,679
  • 6
  • 243
  • 355
  • Oh,I have misunderstand it before.Thanks a lot.. – yode Jun 20 '17 at 21:47
  • a = RandomInteger[1, {10^8}]; (* <-- this is In[136] *) Clear[a]; Unprotect[Out]; Out[136] =.; Protect[Out]; is also a working approach. – LLlAMnYP Jun 21 '17 at 13:36