[Project_owners] clearing variables

Konstantin Svist fry.kun at gmail.com
Tue Feb 7 09:57:34 EST 2006


Garbage collectors usually check for the number of references to the
object - if 0, object is deleted, if not - more complicated algorithm
is required to figure out if it's still referenced -- but often times
GC just leaves the object alone (this is why circular references are
such a pain)

So, if you have a reference to child of a:
var a = Object();
a.foo = Object();
a.foo.bar = 'bar';
b = a.foo;
delete a;
alert(b.bar);

...or reference to a itself:
var a = Object();
a.foo = 'bar';
b = a;
delete a;
alert(b.foo);

...it prints 'bar', which means the property is in fact not deleted
since it's still referenced by b. Of course, if you are sure you have
no references to children of a, you can just leave it at "delete a;"
and let garbage collector do the rest (even if technically it's still
there in the memory, it's impossible to get from within JS, and pretty
hard from browser - though if someone can execute malicious code in
browser, this is the least of your problems).



On 2/7/06, Eric H. Jung <grimholtz at yahoo.com> wrote:
> I suppose that question can be answered by someone who knows whether or
> not properties of a variable are deleted when the variable itself is
> deleted. Anyone?
>
> --- Rod Whiteley <rod.whiteley at gmail.com> wrote:
>
> > Neil wrote:
> > >>  // Recursively delete sensitive data
> > > ...
> > > function wipe(o) {
> > >   for (var i in o) {
> > >     var m = o[i];
> > >     delete o[i];
> > >     if (typeof m == "object")
> > >       wipe(m);
> > >   }
> > > }
> >
> > Is wipe(o) different enough from delete o to make it useful?
> >
> > Does anyone think this really deletes data?
> >
> > --
> > Rod Whiteley
> > _______________________________________________
> > 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