4
$\begingroup$

I recently found that the CleanSlate package allows you to free memory without restarting the Wolfram kernel. The CleanSlate package includes the ClearInOut, which resets the $Line to 1. However, I wonder if there's a way to clear a specific In/Out pair without deleting every other cell preceding the current one. Is there such a way?

$\endgroup$
1
  • 1
    $\begingroup$ Can you not just delete the variable using ?Clear or ?ClearAll to free up memory? $\endgroup$ – CasperYC Jan 6 '20 at 3:45
4
$\begingroup$

Maybe something like this?

a;
Unprotect /@ {In, Out};
In[1] =.; Out[1] =.;
Protect /@ {In, Out};
DownValues /@ {In, Out}
{
  {HoldPattern[In[2]] :> (Unprotect /@ {In, Out}; ), 
   HoldPattern[In[3]] :> (In[1] =. ; Out[1] =. ; ), 
   HoldPattern[In[4]] :> (Protect /@ {In, Out}; ), 
   HoldPattern[In[5]] :> DownValues /@ {In, Out}
  }, 
  {HoldPattern[Out[2]] :> {{"In"}, {"Out"}}, 
   HoldPattern[Out[3]] :> Null, 
   HoldPattern[Out[4]] :> {{"In"}, {"Out"}}
  }
}

The key part being Unset to only deal with specific Ins and Outs.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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