Skip to main content
added 309 characters in body
Source Link
Jason B.
  • 70.2k
  • 3
  • 144
  • 298

The main answer to the question is as follows: don't make circular references. If you think you might accidentally make them, then don't use ExpressionStore.

However, if through some unfortunate coding choices, you think you have circular references, just clear out everything from the store.

You can manually clear an expression store using something like

store["remove"[#]] & /@ store["listTable"[]][[All, 1]];

I like the functionality you get with the expression store, but I very much dislike the syntax for using them. So I made a wrapper called WeakHashTable with a syntax closer to the "HashTable" data structure.

Using that function you would do something like

table = WeakHashTable["example table 1"]
(* define a and b *)
table["Insert", a, "key", b]
table["Insert", b, "key", a]
(* realize you have a leak *)
table["KeyDropAll"]

You can manually clear an expression store using something like

store["remove"[#]] & /@ store["listTable"[]][[All, 1]];

I like the functionality you get with the expression store, but I very much dislike the syntax for using them. So I made a wrapper called WeakHashTable with a syntax closer to the "HashTable" data structure.

Using that function you would do something like

table = WeakHashTable["example table 1"]
(* define a and b *)
table["Insert", a, "key", b]
table["Insert", b, "key", a]
(* realize you have a leak *)
table["KeyDropAll"]

The main answer to the question is as follows: don't make circular references. If you think you might accidentally make them, then don't use ExpressionStore.

However, if through some unfortunate coding choices, you think you have circular references, just clear out everything from the store.

You can manually clear an expression store using something like

store["remove"[#]] & /@ store["listTable"[]][[All, 1]];

I like the functionality you get with the expression store, but I very much dislike the syntax for using them. So I made a wrapper called WeakHashTable with a syntax closer to the "HashTable" data structure.

Using that function you would do something like

table = WeakHashTable["example table 1"]
(* define a and b *)
table["Insert", a, "key", b]
table["Insert", b, "key", a]
(* realize you have a leak *)
table["KeyDropAll"]
added 300 characters in body
Source Link
Jason B.
  • 70.2k
  • 3
  • 144
  • 298

How to avoid circular references? Be careful not to make them.

The codeYou can manually clear an expression store using something like

{store["put"[a, "x",store["remove"[#]] b]],& store["put"[b,/@ "x"store["listTable"[]][[All, a]]}1]];

is what I would write in a tutorial on how to make a memory leak using weak hash table. In fact it is similar tolike the last "Possible issues" example forfunctionality you get with the expression store, but I very much dislike the syntax for using them. So I made a wrapper called WeakHashTableWeakHashTable function I created aswith a wrapper for expression storessyntax closer to the "HashTable" data structure.

Using that function you would do something like

table = WeakHashTable["example table 1"]
(* define a and b *)
table["Insert", a, "key", b]
table["Insert", b, "key", a]
(* realize you have a leak *)
table["KeyDropAll"]

How to avoid circular references? Be careful not to make them.

The code

{store["put"[a, "x", b]], store["put"[b, "x", a]]}

is what I would write in a tutorial on how to make a memory leak using weak hash table. In fact it is similar to the last "Possible issues" example for the WeakHashTable function I created as a wrapper for expression stores.

You can manually clear an expression store using something like

store["remove"[#]] & /@ store["listTable"[]][[All, 1]];

I like the functionality you get with the expression store, but I very much dislike the syntax for using them. So I made a wrapper called WeakHashTable with a syntax closer to the "HashTable" data structure.

Using that function you would do something like

table = WeakHashTable["example table 1"]
(* define a and b *)
table["Insert", a, "key", b]
table["Insert", b, "key", a]
(* realize you have a leak *)
table["KeyDropAll"]
Source Link
Jason B.
  • 70.2k
  • 3
  • 144
  • 298

How to avoid circular references? Be careful not to make them.

The code

{store["put"[a, "x", b]], store["put"[b, "x", a]]}

is what I would write in a tutorial on how to make a memory leak using weak hash table. In fact it is similar to the last "Possible issues" example for the WeakHashTable function I created as a wrapper for expression stores.