In order to monitor memory usage you can call System.totalMemory:
trace(System.totalMemory);
The most common reason why memory leaks occur is that we add event listeners with strong references to objects, which prevents those objects from being garbage collected. As a best practice to prevent this, you should always use weak references when creating event listeners:
label.addEventListener(MouseEvent.Click, handleMouseClick, false, 0, true);instead of
label.addEventListener(MouseEvent.Click, handleMouseClick);Grant Skinner discusses the importance of weak references and resource management in more detail on his blog.
No comments:
Post a Comment