.....
이벤트 리스너가 불필요하게 되었을 경우는,removeEventListener() (을)를 호출하고, 이벤트 리스너를 삭제합니다.삭제하지 않는
경우, 메모리의 문제가 발생할 가능성이 있습니다.가베지 컬렉터는 참조를 가지는 오브젝트를 삭제하지 않기 때문에, 등록되어 있는 이벤트 리스너에
관계한 오브젝트는 메모리로부터 자동적으로 제거 되지 않습니다.
.....addEventListener(MouseEvent.CLICK, mylistener, true|false, 0, true);와 같이 마지막 인자를 true로 해주셔야 약참조를 통해 가비지컬렉터가 회피하지 않도록 하시는게 메모리 누수 문제를 조금이나마 피해 갈 수 있습니다. 그리고, 사용자 이벤트를 만들 때 타입을 "click"과 같이 플렉스 또는 에어가 사용하는 이름으로 만드시면 충돌이 일어날 경우가 있기 때문에 다른 이름의 타입을 정의하시는 것이 좋습니다.
....등록 후에 리스너에서 처리 한 후 반드시 리스너를 제거해 주시는 로직 또한 메모리 누수 문제를 최소화 하는데 도움이 됩니다
....프로파일러를 사용해 GC버튼을 클릭한다고 바로 메모리가 반환 되지 않습니다. 참조를 없애면 GC의 대상이 되지만 바로 반환 되지 않고 어플리케이션에 의해 새로운 메모리가 필요해 질 경우 GC가 활동을 합니다. 만약 아무 어플리케이션 내에서 액션없이 멈춰 있는 상태라면 GC는 아무 일도 하지 않습니다.
리스너는 사용 후 제거
약참조 인자를 true 로
약참조이라서 그런지, 본인이 잘못 해서 그런지
가끔 원치 않을 때 잃어버리는 경우가 생긴다.--;
new Array(); 는 느려진다네요.
System.gc()
| unloadAndStop | () | method |
public function unloadAndStop(gc:Boolean = true):void
| Language Version: | ActionScript 3.0 |
| Runtime Versions: | Flash Player 10, AIR 1.5 |
Attempts to unload child SWF file contents and stops the execution of commands from loaded SWF files. This method attempts to unload SWF files that were loaded usingLoader.load() or Loader.loadBytes() by removing references to EventDispatcher, NetConnection, Timer, Sound, or Video objects of the child SWF file. As a result, the following occurs for the child SWF file and the child SWF file's display list:
- Sounds are stopped.
- Stage event listeners are removed.
- Event listeners for
enterFrame,frameConstructed,exitFrame,activateanddeactivateare removed. - Timers are stopped.
- Camera and Microphone instances are detached
- Movie clips are stopped.
Parameters
gc:Boolean (default = true) — Provides a hint to the garbage collector to run on the child SWF objects ( true ) or not ( false ). If you are unloading many objects asynchronously, setting the gc paramter to false might improve application performance. However, if the parameter is set to false , media and display objects of the child SWF file might persist in memory after running the unloadAndStop() command. |
http://www.memorymanagement.org/articles/recycle.html#reference.deferred
Understanding garbage collection in Flash Player 9
http://www.adobe.com/devnet/flashplayer/articles/garbage_collection.html
Resource management strategies in Flash Player 9
http://www.adobe.com/devnet/flashplayer/articles/resource_management.html
Garbage Collection and Memory Leaks(flex 에서)
http://blogs.adobe.com/aharui/2007/03/garbage_collection_and_memory.html
가비지 컬렉션에 포함되기 위해서 객체를 유휴(Idle)상태로 놓는다.
- 이벤트와 관련된 객체의 매서드를 등록해지
- 모든 타이머와 인터벌을 중단한다.
- 타임라인의 플레이 헤드를 중단
- 객체가 접근 불가능한 상태가 될 때 아울러 접근이 불가능해지는 모든 객체를 비활성화 시킴.
..from Essential ActionScript 3.0


garbagecollection-hioru.pdf


