Services & Resources / Wolfram Forums
MathGroup Archive
*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
  • Subject: [mg69145] Re: Removal of Temporary symbols
  • From: "Andrew Moylan" <andrew.j.moylan at>
  • Date: Thu, 31 Aug 2006 04:38:56 -0400 (EDT)
  • References: <ecu66i$7hf$><ed0rr9$smo$>
  • Sender: owner-wri-mathgroup at

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

carlos at 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

  • Prev by Date: generalized foldlist problem - part 2
  • Next by Date: Re: Re: Is -1^(2/5) really undefined in R?
  • Previous by thread: Re: Removal of Temporary symbols
  • Next by thread: restart?