4 Replies Latest reply on Aug 5, 2007 11:34 PM by Lacito_Domingo

    Bound methods and garbage collection

    Lacito_Domingo
      Hi,

      In the example you can see that I create a TestClass instance. In the constructor of

      TestClass I set the "f" property. As you can see there are no references to the XClass

      instance but it's "foo" method is extracted from the XClass instance and is stored in the "f"

      property.

      The question:

      Does the garbage collector remove the XClass instance from the memory?

      I think it can't remove it, because the bound method (which is store in "f") reference to it (this).

      (But if I set the "f" property to null the garbage collector will remove it.)

      Can you confirm it?

      Thanks,

      Lacito

      The example:


      class XClass
      {
      function foo():void // bound method defined
      {
      ...
      }
      }

      class TestClass
      {
      protected var f:Function = null;

      public function TestClass()
      {
      f = new XClass().foo();
      }
      }


      ...
      var myTest:TestClass = new TestClass();
      ...