Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You shouldn't attempt to remove object from itself - it is a bad practice, and in AS3 you can't do it for sure.</p> <p>Object <em>may</em> be deleted (i.e. garbage collected) only if there are no references left to that object. Since references always get passed by value and object is generally not aware of which references to it exist, you can't delete object from itself. The only useful thing you can do is to create a method which will clean up all resources used by an instance. Such method will serve as a destructor, but you'll have to call it manually. Don't forget that event listeners will also prevent garbage collection unless you remove them.</p> <p>There is also a difference between <code>delete</code>'ing a property and setting it to <code>null</code>. Effectively <code>delete</code> will remove a property from an instance of dynamic class. Whereas setting property value to <code>null</code> will not remove the property, but erase any reference that was stored there. Therefore both actions will destroy the reference that was stored in some property. Note, that you can't <code>delete</code> an object, only a property.</p> <p>There are certain hacks that can be used to initiate garbage collection in flash players 9 and older ones. However recently <code>System.gc()</code> call got available, which does the same thing. Note, that you can't really rely on the fact that GC will actually be called. This is up to the flash player.</p> <p><strong>Returning to your question:</strong> throwing event and notifying parent that something went wrong is actually a good idea. You should stick to it. Moreover, it is better if parent will know of such event that way, and not when it will discover that some properties got magically nulled.</p> <p>P.S.: Reading Grant Skinner <a href="http://www.gskinner.com/blog/archives/2006/06/as3%5Fresource%5Fma.html" rel="noreferrer">articles on memory</a> in flash player is actually a good idea.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload