Consider the following method commonly used to clear a typical variable:
data = {1, 2, 3}
(* {1, 2, 3} *)
ByteCount[data]
(* 112 *)
Clear[data]
ByteCount[data]
(* 0 *)
No problem. Now, if I store the same information in an indexed variable, problems arise.
mytest[data] = {1, 2, 3}
(* {1, 2, 3} *)
ByteCount[mytest[data]]
(* 112 *)
Clear[mytest[data]]
During evaluation of Clear::ssym: mytest[data] is not a symbol or a string.
ByteCount[mytest[data]]
(* 112 *)
Is there a way to clear the values of indexed values so they don't consume memory?
My primary application requires large volumes of data to be stored in indexed variables, and at appropriate times, I would like to be able to "erase" that data from memory as my datasets are really big (multiple GBs per file).
Following initial comments, I realized I needed to re-word my initial question. (which I've done.) Taking advice from the comments, it seems Unset may be the way to go here.
Notice:
mytest[data] = {1, 2, 3}
(* {1, 2, 3} *)
mytest[data2] = {4, 5, 6, 7}
(* {4, 5, 6, 7} *)
ByteCount[mytest[data]]
(* 112 *)
ByteCount[mytest[data2]]
(* 136 *)
mytest[data] =.
ByteCount[mytest[data]]
(* 48 *)
mytest[data]
(* mytest[data] *)
mytest[data2]
(* {4, 5, 6, 7} *)
As an add on, why is there a small amount of memory still attached to mytest[data] after performing the Unset operation?
ClearAll[mytest]
? $\endgroup$ – kglr Aug 5 '19 at 16:40Unset
:mytest[data] =.
$\endgroup$ – Michael E2 Aug 5 '19 at 16:41Out
so you might need to clear that too if you really need the memory back. $\endgroup$ – b3m2a1 Aug 5 '19 at 16:59Unset
? $\endgroup$ – ktm Aug 5 '19 at 18:26