Tag Info

New answers tagged


On a regular basis i have subkernels eating up my Memory. Still have not a great solution however if finished anyway (Or between two ParallelTables) I handle this problem via: CloseKernels[];LaunchKernels[]; This frees the memory of the subkernels.


The creation of an explicit function f can be completely avoided by using the 3rd argument to Function. There, you can specify what Attributes the anonymous function should have and therefore, you can enforce the same behavior as you did for f. unflatten[l_, o_] := Module[{i = 1, l1 = Flatten[l]}, Function[Null, l1[[i++]], {Listable}][o] ]


Here is an alternative which is a bit shorter and closer to the original, and still completely free of this leak: unflatten[l_, o_] := Module[{res, f, i = 1, l1 = Flatten[l]}, Block[{f}, SetAttributes[f, Listable]; f[_] := l1[[i++]]; f[o]]]


You can fix that with the following change: unflatten[l_, o_] := Module[{f, i = 1, l1 = Flatten[l]}, SetAttributes[f, Listable]; f[_] := l1[[i++]]; With[{res = f[o]}, Clear[f, l1]; res ] ]

Top 50 recent answers are included