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`
WeakHashTable
​
WeakHashTable
["label"]
returns a weak hash table data structure with the given label.
​
Details and Options

Examples  
(7)
Basic Examples  
(1)
As in many examples for this paclet, we set
$HistoryLength
to zero to avoid leaving strong references to expressions in the session history:
In[1]:=
$HistoryLength=0
Out[1]=
0
Create a new table and an expression:
In[2]:=
table=
WeakHashTable
["example table 1"]
Out[2]=
WeakHashTable

example table 1

In[3]:=
expr=RandomImage[4]
Out[3]=
Perform some expensive computation that you wish to cache:
In[4]:=
(data=ImageKeypoints[expr])//Shallow//RepeatedTiming
Out[4]=
{0.00525441,{{88.1816,77.1035},{21.5787,75.5165},{34.8592,15.4442},{94.7895,109.767},{22.5318,15.3431},{49.9019,37.2992},{114.659,79.3872},{58.3214,63.6881},{58.3328,31.0274},{66.9111,97.8033},87}}
Add the data to the table:
In[5]:=
table["Insert",expr,"key",data]
In the above we use
"key"
as the key - any expression can be used as a key, but using simple expressions like strings or symbols is best for efficiency. Verify that the data in the table is the same and that retrieving it is fast:
In[6]:=
SameQ[data,table["Lookup",expr,"key"]]//RepeatedTiming
Out[6]=
{3.12678×
-6
10
,True}
Since the history is turned off
expr
is the only reference to the image expression, deleting it will clear the table:
In[7]:=
table["Length"]
Out[7]=
1
In[8]:=
expr=.
In[9]:=
table["Length"]
Out[9]=
0
In[10]:=
table["Lookup",expr,"key"]
Out[10]=
$Failed
Scope  
(1)

Generalizations & Extensions  
(1)

Possible Issues  
(4)

SeeAlso
SameInstanceQ
 
▪
SetWeakCache
 
▪
CheckWeakCache
 
▪
ClearWeakCache
RelatedGuides
▪
Weak Cache Functions
""

© 2025 Wolfram. All rights reserved.

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