Hi Marius,

yes, you are right, the listener should be removed. A smart solution would be to remove the listener when the class will be disposed, but you can't remove a listener with an anonymous callback method. So the first step is to remove the anonymous calback method and also take care that the listener is only once added. And at the end remove the listener in the destruct method.

Here a example that shows it:

qx.Class.define("my.cool.Class",
{
  // Do stuff...

  members : {
    this.__onUpdateListenerID : null,

    // Do stuff...

    __applyDataModel: function(dataModel) {
      // Do some stuff...

      if (this.__onUpdateListenerID == null) {
this.__onUpdateListenerID = snProxy.addListener("update", this.__onUpdate, this);
      }
    },

    this.__onUpdate :  function() {
        this.debug(this);
        this.debug(this.__rootNode);
        this.debug(this.__rootNode.getChildren());
        this.refreshTree();
    }
  },

  destruct : function() {
    if(this.__onUpdateListenerID != null) {
        // Do stuff to get snProxy
        snProxy.removeListener("update",  this.__onUpdate, this);
    }
});

Cheers,
Chris

Am 23.09.2010 12:15, schrieb Marius Austerschulte:
I think I know the reason now: When the apply-Method is called on my Tree object the first time, I don't get that error, the Tree isn't disposed. When that method is called the second time it's called on a new Tree instance that had been created shortly before. Again, a new snProxy object is created and the "update"-event listener is added to it. However, the old Tree instance still exists together with its snProxy object that still fires the "update"-event although the Tree it is contained in is already disposed (since it is not referenced anymore). Since there are multiple snProxys now the event handler function is called multiple times but only in the last call the event handler function refers to the current non-disposed Tree (I didn't recognize that at first sight because the application broke on an error and stopped running and only let the first "update"-event listener process its code). The snProxy object itself isn't disposed because it is referenced in an event listener of an object that still exists.

So if I add
if (!this.isDisposed()) {
  this.debug(this);
  // do something
}
to the event handler the program runs. But I think this solution is not elegant. The event handler is still called by objects that shouldn't exist anymore. I think I'll try to add a method that removes all the event listeners that could cause such problems.


2010/9/22 Christian Hagendorn <[email protected] <mailto:[email protected]>>

     Am 22.09.2010 16:04, schrieb Marius Austerschulte:
    > Great! That seems to be the reason! this.isDisposed() and
    > this.__rootNode.isDisposed() are both true.
    > But then why is it disposed? I still have a reference that points to
    > that object.
    Hi Marius,

    I don't know what exactly is the reason in your case, maybe your
    application does it. You can try to debug it buy adding a this.trace()
    in the destruct function [1] in the class which has the appear method.
    The stack trace should show how dispose/destroy the qooxdoo object.

    Keep in mind that dispose and destroy has a differer meaning here. It
    just means that a qooxdoo object is cleaned up for garbage
    collection. A
    qooxdoo dispose/destroy removes for example all DOM references so that
    the garbage collector can remove the object from memory if no
    reference
    exist in your application.

    Cheers,
    Chris

    [1]
    
http://manual.qooxdoo.org/1.2.x/pages/core/oo_feature_summary.html#destructor

    
------------------------------------------------------------------------------
    Start uncovering the many advantages of virtual appliances
    and start using them to simplify application deployment and
    accelerate your shift to cloud computing.
    http://p.sf.net/sfu/novell-sfdev2dev
    _______________________________________________
    qooxdoo-devel mailing list
    [email protected]
    <mailto:[email protected]>
    https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel



------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to