Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: Removal of Temporary symbols

  • To: mathgroup at smc.vnet.net
  • Subject: [mg69061] Re: Removal of Temporary symbols
  • From: carlos at colorado.edu
  • Date: Tue, 29 Aug 2006 03:25:46 -0400 (EDT)
  • References: <ecu66i$7hf$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

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