MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Removal of Temporary symbols


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


  • Prev by Date: Re: Re: General--Exponential simplifications by default
  • Next by Date: Re: Selecting Lists Without Null Results
  • Previous by thread: Removal of Temporary symbols
  • Next by thread: Re: Removal of Temporary symbols