[Project_owners] clearing variables

Eric H. Jung grimholtz at yahoo.com
Mon Feb 6 16:54:47 EST 2006


Thank you for the excellent explanation.

By the way, 'foo in this' after 'delete foo' yields 'ReferenceError:
foo is not defined', not false.


--- Konstantin Svist <fry.kun at gmail.com> wrote:

> Very simple,
> foo = null;
> actually assigns value of null to foo - the variable exists and is
> set.
> 
> delete foo;
> actually deletes the variable (garbage collection should happen in
> this case).
> 
> note that 'foo in this' evaluates to false in either one
> 
> You can tell that the two lines above have different actions by
> running a few lines:
>  var a = 'hello';
>  var b = 'world';
>  a = null;
>  delete b;
>  if (a==null) { alert('a is null') }
>  else         { alert('a is not null') }
>  if (b==null) { alert('b is null') }
>  else         { alert('b is not null') }
> 
> 
> The difference is slight but it's definitely there. If you want to
> garbage-collect your variables, use delete.
> 
> HTH
> 
> On 2/6/06, Eric H. Jung <grimholtz at yahoo.com> wrote:
> > Hi,
> >
> > Given the variable "foo" with an arbitrary value, in the context of
> an
> > extension what is the difference between:
> >
> > foo = null;
> > versus
> > delete foo;
> >
> > Does the latter speed garbage collection more than the former?
> >
> > Thanks,
> > Eric Jung
> >
> > _______________________________________________
> > Project_owners mailing list
> > Project_owners at mozdev.org
> > http://mozdev.org/mailman/listinfo/project_owners
> >
> _______________________________________________
> Project_owners mailing list
> Project_owners at mozdev.org
> http://mozdev.org/mailman/listinfo/project_owners
> 



More information about the Project_owners mailing list