[Prototype-core] Re: Free a class from memory

2008-07-17 Thread Ryan Gahl
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; iemptyList.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 prototype-core@googlegroups.com
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
-~--~~~~--~~--~--~---



[Prototype-core] Re: Free a class from memory

2008-07-17 Thread mtjs

Thanx for the replys.

I am setting up event handles with 'observe'. I also use
bindAsEventListener.
Isn't it enough to do a 'stopObserving' on the events ?

To know if I have a 'memory leak' (and to determing that the null'ing
didn't work) I look @ the ... memory the browser is using. If it goes
up, I have a leak. (if I add nothing to the page ofcoz :)) If I null
the top reference, I have lesser memory that is added then if I don't
do it, but since there was still mem addes, I figured it wasn't
enough.

Is there some kind of documentation on what you should watch to not
create memory leaks ? Also is there some kind of tool to correctly see
if you have memory leaks?

Kind regards,

Mtjs.

On Jul 17, 3:44 pm, Ryan Gahl [EMAIL PROTECTED] wrote:
 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; iemptyList.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, LLChttp://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- Hide quoted text -

 - Show quoted text -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
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
-~--~~~~--~~--~--~---



[Prototype-core] Re: Free a class from memory

2008-07-17 Thread Ryan Gahl
When you do your stopObserving, you need to make sure you are passing the
exact function handler you used when registering the event.

var handler = function() { blah(); }.bindAsEventListener(this);
Event.observe(someElement, click, handler);

...later:
Event.stopObserving(someElement, click, handler);


NOTE: this is not going to work:
Event.observe(someElement, click, function() { blah();
}.bindAsEventListener(this));
Event.stopObserving(someElement, click, ???); //notice I don't have a
handle to that anonymous function I defined above so I can't stop observing
it



On Thu, Jul 17, 2008 at 9:45 AM, mtjs [EMAIL PROTECTED] wrote:


 Thanx for the replys.

 I am setting up event handles with 'observe'. I also use
 bindAsEventListener.
 Isn't it enough to do a 'stopObserving' on the events ?

 To know if I have a 'memory leak' (and to determing that the null'ing
 didn't work) I look @ the ... memory the browser is using. If it goes
 up, I have a leak. (if I add nothing to the page ofcoz :)) If I null
 the top reference, I have lesser memory that is added then if I don't
 do it, but since there was still mem addes, I figured it wasn't
 enough.

 Is there some kind of documentation on what you should watch to not
 create memory leaks ? Also is there some kind of tool to correctly see
 if you have memory leaks?

 Kind regards,

 Mtjs.

 On Jul 17, 3:44 pm, Ryan Gahl [EMAIL PROTECTED] wrote:
  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; iemptyList.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, LLChttp://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- Hide quoted text -
 
  - Show quoted text -
 



-- 
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 prototype-core@googlegroups.com
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
-~--~~~~--~~--~--~---