MathGroup Archive 2011

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

Search the Archive

Re: Quit versus Clear["Global`*"]

  • To: mathgroup at
  • Subject: [mg121241] Re: Quit versus Clear["Global`*"]
  • From: "Oleksandr Rasputinov" <oleksandr_rasputinov at>
  • Date: Tue, 6 Sep 2011 03:55:12 -0400 (EDT)
  • Delivered-to:
  • References: <> <j3u7r6$a88$>

This is not a side-effect; it is necessary in order for the symbol to be  
removed. Retaining any references whatsoever will prevent the symbol from  
being deleted from the symbol table due to Mathematica's  
reference-counting garbage collection. When calling Remove, one explicitly  
requests that the symbol be completely removed, and this is duly performed  
along with all that it implies. If one only wishes to clear the  
definitions on a symbol rather than destroying the symbol itself, the use  
of Remove would be erroneous, since this quite separate operation is the  
domain of ClearAll.

A situation in which Remove might be needed is where a function has  
created temporary symbols and wishes to destroy them before returning in  
order to avoid clogging up the symbol table (which would represent a  
memory leak and may slightly worsen Mathematica's performance). Although  
the Temporary attribute could be used instead, catching all the references  
may not be easy, so Remove is helpful in that it automatically invalidates  
any references that would otherwise have prevented garbage collection. In  
other words, Remove is a specialised function with a specialised use, not  
simply an alternative to Clear/Unset et al.

On Mon, 05 Sep 2011 12:07:23 +0100, DrMajorBob <btreat1 at>  

> Your experiment makes Remove look useful (possibly), but here's one that
> does not:
> ClearAll[f]
> f[x_] := Plot[x, {x, 0, 1}] SetAttributes[f, Listable]
> Remove[x]
> ?? f
> Remove[x] cripples f without mentioning it, which I'd call a very ugly
> side-effect.
> Bobby
> On Sun, 04 Sep 2011 17:05:26 -0500, Murray Eisenberg
> <murray at> wrote:
>> Try the following little three-part experiment.  In each part, the last
>> step tells you what Mathematica now knows about the symbol f.
>>     f[x_] := Plot[x, {x, 0, 1}]
>>     SetAttributes[f, Listable]
>>     Clear[f]
>>     ??f
>>     f[x_] := Plot[x, {x, 0, 1}]
>>     SetAttributes[f, Listable]
>>     ClearAll[f]
>>     ??f
>>     f[x_] := Plot[x, {x, 0, 1}]
>>     SetAttributes[f, Listable]
>>     Remove[f]
>>     ??f
>> On 9/4/11 4:12 AM, AES wrote:
>>> In article<j3u7r6$a88$1 at>,
>>>   Murray Eisenberg<murray at>  wrote:
>>>> First, Clear, whether for a single object or an entire list of  
>>>> objects,
>>>> does not remove their Attributes, e.g., just their values. You might
>>>> want ClearAll instead.
>>> And how do either of those differ from Remove?

  • Prev by Date: Re: Running notebook from command line
  • Next by Date: Re: Quit versus Clear["Global`*"]
  • Previous by thread: Re: Quit versus Clear["Global`*"]
  • Next by thread: Re: Quit versus Clear["Global`*"]