David Lawson
David Lawson

Reputation: 7922

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

Upvotes: 5

Views: 2728

Answers (2)

gruhm
gruhm

Reputation: 63

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.

Upvotes: 4

ldindu
ldindu

Reputation: 4380

You can implement your dismissViewControllerAnimated method call in following way.

[self dismissViewControllerAnimated:NO completion:^{
    // release the SKScene here....
}];

Upvotes: 0

Related Questions