Wolfram Language Paclet Repository

Community-contributed installable additions to the Wolfram Language

Primary Navigation

    • Cloud & Deployment
    • Core Language & Structure
    • Data Manipulation & Analysis
    • Engineering Data & Computation
    • External Interfaces & Connections
    • Financial Data & Computation
    • Geographic Data & Computation
    • Geometry
    • Graphs & Networks
    • Higher Mathematical Computation
    • Images
    • Knowledge Representation & Natural Language
    • Machine Learning
    • Notebook Documents & Presentation
    • Scientific and Medical Data & Computation
    • Social, Cultural & Linguistic Data
    • Strings & Text
    • Symbolic & Numeric Computation
    • System Operation & Setup
    • Time-Related Computation
    • User Interface Construction
    • Visualization & Graphics
    • Random Paclet
    • Alphabetical List
  • Using Paclets
    • Get Started
    • Download Definition Notebook
  • Learn More about Wolfram Language

WeakCache

Guides

  • Weak Cache Functions

Symbols

  • CheckWeakCache
  • CleanupAfter
  • ClearHistory
  • ClearWeakCache
  • CreateReference
  • SameInstanceQ
  • SetWeakCache
  • StrongReference
  • WeakHashTable
  • WeakReference
JasonB`WeakCache`
CreateReference
​
CreateReference
[expr]
returns a strong reference to the input expression.
​
​
CreateReference
[expr,"Weak"]
returns a weak reference to the input expression.
​
Details and Options

Examples  
(2)
Basic Examples  
(2)
Create an object during and return a strong reference to it:
In[1]:=
$HistoryLength=0;
In[2]:=
SeedRandom[42];​​obj=RandomGraph[{10,15}];​​
CleanupAfter
[obj,Echo["deleting obj now"]];​​ref=
CreateReference
[obj]
Out[2]=
<
StrongReference
>
CleanupAfter
is used above to demonstrate when the underlying object is deleted from memory. Clearing the variable obj does not delete all references to the data:
In[3]:=
obj=.
You can still retrieve the stored object using the following notation:
In[4]:=
ref[]
Out[4]=
Note that
ref
is not equal to
obj
:
In[5]:=
ByteCount/@{ref,ref[]}
Out[5]=
{40,888}
ref
is now the only reference to the underlying data, and deleting it will delete the data:
In[6]:=
ref=.
»
deleting obj now
​
Create an object during and return a weak reference to it:
In[1]:=
$HistoryLength=0;
In[2]:=
obj=RandomGraph[{10,15}];​​
CleanupAfter
[obj,Echo["deleting obj now"]];​​ref=
CreateReference
[obj,"Weak"]
Out[2]=
<WeakReference>
CleanupAfter
is used above to demonstrate when the underlying object is deleted from memory. Clearing the variable obj will delete all references to the data:
In[3]:=
obj=.
»
deleting obj now
You can no longer retrieve the stored object using the weak reference:
In[4]:=
ref[]
Out[4]=
Failure

Message:
The reference has expired.
Tag:
ExpiredReference

SeeAlso
WeakReference
 
▪
WeakHashTable
RelatedGuides
▪
Weak Cache Functions
""

© 2025 Wolfram. All rights reserved.

  • Legal & Privacy Policy
  • Contact Us
  • WolframAlpha.com
  • WolframCloud.com