Manually nulling the top level reference should work just fine, as long as
there are no other references to the object in other scopes. Another big one
to check is DOM event handlers... are you setting any up? If so, part of
your destroying should include unattaching them first...


On Thu, Jul 17, 2008 at 8:34 AM, kangax <[EMAIL PROTECTED]> wrote:

>
> On Jul 17, 9:09 am, mtjs <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > I have something like this :
> >
> >       var myTestClass=Class.create({
> >         initialize:function(opt) {
> >           this.child=null;
> >
> >           // do stuff that uses mem
> >           // like create and show divs
> >           // and so on
> >
> >         },
> >         myFnc:function(param) {
> >
> >         }
> >       });
> >
> > With this class I build a 'tree'.
> >   (
> >     in real life I use other code to do this : the child is assigned
> >     from within the class, but that doesn't matter for my question
> >   )
> >
> >      var myOne=new myTestClass();
> >      myOne.child=new myTestClass();
> >      myOne.child.child=new myTestClass();
> >      myOne.child.child.child=new myTestClass();
> >
> > I don't know how much childs there are, yet I want to free all the
> > memory.
> >
> > Main question :
> >
> >   how can I do that ?
> >
> >   can I do it by : myOne=null;
> >
> >   should I free every instance ?
> >   I tried it with a loop, first adding all childs to an array (if I
> > set the 'parent'
> >   to 'null', I can't see what's in it anymore)
> >
> >       var emptyList=new Array();
> >       var tmp=myOne;
> >       while (tmp) {
> >         emptyList.push(tmp);
> >         tmp=tmp.child;
> >       }
> >       for (var i=0; i<emptyList.length; i++) {
> >         emptyList[i]=null;
> >       }
> >   This doesn't work: the 'reference' to the instance in 'emptyList[n]'
> > is a copy, not a
> >   'reference' so I just use more memory and then empty it again, yet I
> > don't free the
> >   tree I've made in 'myOne'. (so far as I tested)
> >
> >   can I destroy it from within 'myOne' (with a destory function or
> > something like that)
> >     (I tried this=null in the class but that doesn't work ;))
>
>
> All objects are actually "passed by reference" (including function
> ones). Only primitives are copied. How exactly did you determine that
> manual "nulling" doesn't work and only consumes more memory?
>
> -- kangax
> >
>


-- 
Ryan Gahl
Manager, Senior Software Engineer
Nth Penguin, LLC
http://www.nthpenguin.com
--
WebWidgetry.com / MashupStudio.com
Future Home of the World's First Complete Web Platform
--
Inquire: 1-920-574-2218
Blog: http://www.someElement.com
LinkedIn Profile: http://www.linkedin.com/in/ryangahl

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to