我有一個用於刪除實例並將其替換爲另一個實例的函數的問題。基本上,它保存在內存中的項目,無論如何。在對象內部,我有弱聽者,並且在它被移除後我將所有內容都清空,但是我運行的函數檢查它是否仍然活動,告訴我它(僅僅是一個Event.ENTER_FRAME跟蹤一些帶有弱鏈接的文本)。這是一個刪除實例的功能,將其從階段中刪除並將其刪除,但它不會將其從內存中刪除
即使當我從我加載的實例中刪除所有內容時,它仍然似乎留在內存中,根據我的蹤跡它仍然是。如何從內存中徹底刪除某些東西,而不是將它從舞臺上刪除後將其全部刪除?我沒看到什麼嗎?
這是函數:
private function loadArea(inputArea:String)
{
//This is for a checker to make sure that areas only get loaded once.
currentRoom = inputArea;
//If the area currently loaded is not null, make it null now.
if(selectedArea != null) selectedArea = null;
//Null any data inside of the reference used to create the name of the new area.
areaReference = null;
//Grab the class using the input.
areaReference = getDefinitionByName(inputArea + "Area") as Class;
//Null the sprite used to house the class
areaSprite = null;
//Set the holder as a new instance of the desired class.
areaSprite = new areaReference() as Sprite;
//If the selected area is still not null for some reason,
if(selectedArea != null)
{
//Remove the area from the container...
areaContainer.removeChild(selectedArea);
//...and nullify it.
selectedArea = null;
}
//Set the current area as the newly created instance.
selectedArea = areaSprite;
//If the area is not the "Game", load in the assets one way,
if(inputArea != "Game") selectedArea.construct(areaAssets);
//otherwise do it another way.
else selectedArea.construct(newScreenData,apiServer,cdnServer,areaAssets);
//This is for a checker that fades out the screen, which it needs to fade back in soon.
newScreenData = null;
//While the container for areas has any areas inside of it, remove them.
while(areaContainer.numChildren) areaContainer.removeChildAt(0);
//...then add the new instance area to the container.
areaContainer.addChild(selectedArea);
//...then let all the parts of the game know that a new area has been laoded in.
Global.echoEvent.echo("gameBootUp","playAreaIn");
}
是否引用了全局的東西將它保存在內存中?我有一個全局變量用於派發DataEvents發送字符串。我從實例內部添加一個事件監聽器,因此它可以從其他實例接收事件。我雖然刪除了監聽器,但我不確定是否還有其他問題繞着我可能還不知道的全局變量出現問題? –