Re: Removal of Temporary symbols

*To*: mathgroup at smc.vnet.net*Subject*: [mg69145] Re: Removal of Temporary symbols*From*: "Andrew Moylan" <andrew.j.moylan at gmail.com>*Date*: Thu, 31 Aug 2006 04:38:56 -0400 (EDT)*References*: <ecu66i$7hf$1@smc.vnet.net><ed0rr9$smo$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Thanks Carlos. I have been using the Remove function in order to ensure that my unreferenced temporary symbols don't take up memory. Should I prefer to use ClearAll instead? I can't find a compelling reason to choose one over the other. Anyway, does anyone know whether or not it is by design that unreferenced temporaries are not always detected and removed? I think it's important to know the conditions under which temporaries won't be removed, so that we can now when it is necessary to explicitly call ClearAll or Remove, and so that the memory footprint of a function is predictable. carlos at colorado.edu wrote: > Andrew Moylan wrote: > > Hi, > > > > Can you help me understand the conditions under which Mathematica > > automatically removes symbols with the attribute Temporary that are > > created by calls to Module? Please consider the following code: > > > > $Context="test`" > > > > Module[{x, y}, > > y[] = 0; > > x = y; > > ] > > > > Names["test`*"] > > > > For me the result of the call to Names is something like {y, y$18}. Why > > is the temporary variable y$18, which is no longer referenced by > > anything, not being automatically removed? > > > > > If explicit deletion of temporaries is desirable, for example to free > memory taken up by a large list or array, use ClearAll > before module return. I do that for graphic modules that build > large plot files. > > > If I remove the line "x = y;" from the above code, the temporary > > variable is destroyed as expected, and the result of the call to Names > > is {y}. I'm not clear on why the symbol "y" has been created in the > > global ("test`") context in this case; but I'm not bothered by it > > (because, unlike the preservation of temporary variables, it doesn't > > represent an O(n) memory overhead for evalutating my Module n times). > > Can anyone explain this behaviour? > > > > Cheers, > > > > Andrew