SKScene Fails to deallocate memory resulting in bounded memory growth

后端 未结 3 1089
暖寄归人
暖寄归人 2021-01-06 01:05

I have been struggling with this for days, for some reason my SKScenes are not deallocating correctly, this results in bounded memory growth as each time i exit and enter a

3条回答
  •  抹茶落季
    2021-01-06 01:09

    Based on your posted code, I suggest you add this to your MainMenu:

    -(void) willMoveFromView:(SKView *)view {
        [self removeAllChildren];
    
        backgroundImage = nil;
        topBar = nil;
        bottomBar = nil;
        ladybirds = nil;
        title = nil;
        subtitle = nil;
        coffee = nil;
        settingsWin = nil;
        iapWin = nil;
        unlocksWin = nil;
        startButton = nil;
        continueButton = nil;
        settingsButton = nil;
        iapButton = nil;
        unlocksButton = nil;
        theParticles = nil;
    }
    

    Add this to your SettingsScene:

    -(void) willMoveFromView:(SKView *)view {
        [self removeAllChildren];
    
        backButton = nil;
        resetButton = nil;
        resetTutorialsButton = nil;
        creditsButton = nil;
        titleLabel = nil;
        copyrightLabel = nil;
        resetGameAlert = nil;
        resetTutAlert = nil;
        theScene = nil;
        theTransition = nil;
        menuBg = nil;
    }
    

    Keep in mind that SK uses its own caching which you have no control over. This means you will see an increase in memory the first couple of times you switch scenes but it will level out at some point. I suggest you move back and forth 15 to 20 times and see what happens.

提交回复
热议问题