Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpriteKit scene not being released

I have a main menu which launches a view controller with an SKView/SKScene via a modal segue. I then call dismissViewControllerAnimated, which returns the app to the main menu, but I can still hear sound effects from the SKScene. When I relaunch the SKScene multiple times the app eventually crashes.

I've tried following a heapshot analysis tutorial (http://www.friday.com/bbum/2010/10/17/when-is-a-leak-not-a-leak-using-heapshot-analysis-to-find-undesirable-memory-growth/) but I don't seem to be getting anywhere. I've made sure to deallocate all strong @properties...

Any ideas on what might be causing this issue? Would any code/screenshots be helpful, or can I provide any information to help narrow down the issue?

Instruments

like image 741
David Lawson Avatar asked Oct 03 '22 02:10

David Lawson


1 Answers

It is difficult to know from the information provided. I can tell you I had a similar issue and it turned out to be related to SKAction objects. I was cacheing the Actions as properties of the scene and then having child nodes run those actions. I found that ensuring that the child nodes called removeAllActions eliminated the issue for me. Something along the lines of:

-(void) willMoveFromView:(SKView *)view
{
   [self.children enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        SKNode* child = obj;
        [child removeAllActions];
    }];

    [self removeAllChildren];
}

Not sure if this is what you're facing, but may be something to look out for.

like image 93
gruhm Avatar answered Oct 12 '22 23:10

gruhm