# How to release the space took up by specify variable [duplicate]

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?

• Have you tried $HistoryLength=0 and Clear[a]? Jun 20, 2017 at 20:09 • @CarlWoll Yes,I have.But it don't work.. – yode Jun 20, 2017 at 21:19 • We really need a canonical question for this sort of problem. It's not clear, it's not easy to find in the documentation, it has finer points such as the requirement to delete the Out cells and make sure they're not anywhere in the DownValues for Out either. I say, this should stay open. Jun 22, 2017 at 6:03 • – Kuba Dec 10, 2018 at 7:47 ## 1 Answer 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

• Oh,I have misunderstand it before.Thanks a lot..
– yode
Jun 20, 2017 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. Jun 21, 2017 at 13:36