3 Replies Latest reply on Mar 13, 2008 8:38 AM by Gregory Lafrance

    delete all references to an object

    gordon.franke
      I have a class that is bindable and has 3 properties _tree(Array), _projects(Array) and _projectMap(Object).

      I have many Objects in this 3 properties so i have a tree(_tree) i can filter for all projects(_projects) and can access a project by his id(_projectMap).

      Now i run into a problem how can i delete a project and all references to it so that is completely remove from the memory.

      Is there a simple way to delete the object and all his references?

      At the moment i delete it manually:

      _tree:
      var index:int = treeData.getItemIndex(project);
      treeData.removeItemAt(index);

      _projectMap:
      delete this._projectMap[project.id];

      _projects:
      for(var i:int=0;i < this._projects.length;i++)
      {
      if(this._projects .id == project.id)
      {
      this._projects.splice(i,1);
      break;
      }
      }
        • 1. Re: delete all references to an object
          Gregory Lafrance Level 6
          Remember to use removeEventListener before deleting objects, for each event listener added to object, otherwise a reference will still remain in memory after deleting the object.
          • 2. Re: delete all references to an object
            gordon.franke Level 1
            ok but is there a function to check if a object has references?
            or a simple function to delete all references and the object?
            • 3. Re: delete all references to an object
              Gregory Lafrance Level 6
              I don't think so. See FB 2.0.1 help topic "Object creation and destruction" or LiveDocs:

              Destroying unused objects
              ...
              To ensure that the garbage collector destroys your unused objects, remove all references to that object, including the parent's reference to the child.

              On containers, you can call the removeChild() or removeChildAt() method to remove references to child controls that are no longer needed.
              ...
              You can clear references to unused variables by setting them to null in your ActionScript; for example:

              myDataProvider = null
              ...
              To ensure that destroyed objects are garbage collected, you must also remove event listeners on them by using the removeEventListener() method
              ...
              You cannot call the removeEventListener() method on an event handler that you added inline in MXML.
              ...
              The weakRef parameter to the addEventListener() method provides you with some control over memory resources for listeners. A strong reference (when weakRef is false) prevents the listener from being garbage collected. A weak reference (when weakRef is true) does not. The default is false.