Skip to content

A tool for automatic cleanup when Wolfram Language expressions go out of scope.

License

Notifications You must be signed in to change notification settings

jasondbiggs/ExpressionCleanup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ExpressionCleanup

AddCleanupFunction[expr, func] will call func when all references to expr are gone.

Cleanup[expr] will call any cleanup code that has been registered for expr, and Cleanup[] will call all registered cleanup code. All cleanup code is called when the kernel exits cleanly.

Note that 'references' includes anything in the output history, anything accessible via % or Out[..]. In the example below, $HistoryLength is set to zero otherwise Out[4] would have kept the expression still available.

In[1]:= PacletDirectoryLoad[pathToGitCheckout];

In[2]:= << ExpressionCleanup`
(*library will be built if need be*)

In[3]:= $HistoryLength = 0

Out[3]= 0

In[4]:= f = {1, 2, 3}

Out[4]= {1, 2, 3}

In[5]:= AddCleanupFunction[f,
  Print["calling deletion code"];
  Print["use any compound expression"];
]

In[6]:= f =.

During evaluation of In[6]:= calling deletion code

During evaluation of In[6]:= use any compound expression

About

A tool for automatic cleanup when Wolfram Language expressions go out of scope.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published