Am I going about cleaning up the listeners and references the correct way?
I have wrote a function (below) which removes listeners and calls a similar function in many of the classes.
It then sets the references to null.
public function removeAllEventListeners():void
{
//Kill listeners in this class
_dragHandler.removeEventListener(MegaZineEvent.PAGE_CHANGE, onPageChange);
_slideTimer.removeEventListener(TimerEvent.TIMER, onSlideTimer);
removeEventListener(Event.ENTER_FRAME, redraw);
//NEED to check *************************************************** //
//xmlLoader.addEventListener(Event.COMPLETE, onXMLLoaded);
//xmlLoader.addEventListener(IOErrorEvent.IO_ERROR, onXMLError);
//***************************************************************** //
for(var i = 0; i < _pages.length; i++)
{
(_pages[i] as Page).removeEventListener(MegaZineEvent.PAGE_COMPLETE, onPageLoaded);
}
_library.removeEventListener(MegaZineEvent.LIBRARY_COMPLETE, onLibraryComplete);
_library.removeEventListener(MegaZineEvent.LIBRARY_ERROR, onLibraryError);
_navigation.removeEventListener(NavigationEvent.BUTTON_CLICK, onNavigationMenu);
_settings.removeEventListener("closed", onModalWindowClose);
_zoomContainer.removeEventListener(MegaZineEvent.ZOOM_CLOSED, onZoomClose);
_passwordForm.removeEventListener(MegaZineEvent.PASSWORD_CORRECT, onPasswordCorrect);
_help.removeEventListener("closed", onModalWindowClose);
//Call functions to kill other class listeners
_dragHandler.removeAllEventListeners();
_library.removeAllEventListeners();
_navigation.removeAllEventListeners();
_settings.removeAllEventListeners();
_zoomContainer.removeAllEventListeners();
_passwordForm.removeAllEventListeners();
_help.removeAllEventListeners();
_pageLoader.removeAllEventListeners();
//Remove References by setting to null or undefined
_dragHandler = null;
_library = null;
_navigation = null;
_settings = null;
_zoomContainer = null;
_passwordForm = null;
_help = null;
_localizer = null;
_pageLoader = null;
}
If anyone can suggest anything to kill the memory leak I'd appreciate it.
Cheers
Jay