[Project_owners] clearing variables

Konstantin Svist fry.kun at gmail.com
Mon Feb 6 15:38:18 EST 2006


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
>


More information about the Project_owners mailing list