5

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

David Lawson
  • 7,163
  • 4
  • 28
  • 36
  • 2
    ARC enabled? Check all strong instances, do you store any of them outside the skview/skscene or sk view controller instances? Another common error is a retain cycle common to graph structures, for example when one node keeps a strong reference to one of its parent or sibling nodes (make those weak). – LearnCocos2D Dec 18 '13 at 15:46
  • Yeah, using ARC. Re. your second question, any class that has strong instances sets them to nil in either viewDidUnload or dealloc, is that not enough? I'll delve into the code to investigate your last point. – David Lawson Dec 18 '13 at 15:52
  • Unfortunately fixing all the retain cycles I could find didn't seem to help... – David Lawson Dec 18 '13 at 16:04
  • Have you tried dismissing the VC another way - like an unwind segue? – AndyOS Dec 18 '13 at 17:19
  • dealloc is too late to break a retain cycle! If theres a retain cycle dealloc won't run. – LearnCocos2D Dec 18 '13 at 20:32
  • I fixed the retain cycles by changing them from strong to weak – David Lawson Dec 18 '13 at 23:49
  • 1
    Turns out it was due to this: http://cocoa.tumblr.com/post/62812809698/uiviewcontroller-transitioning-delegate-retain-cycle - @LearnCocos2D feel free to put reference cycles as an answer – David Lawson Dec 19 '13 at 00:12

2 Answers2

4

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.

gruhm
  • 63
  • 5
0

You can implement your dismissViewControllerAnimated method call in following way.

[self dismissViewControllerAnimated:NO completion:^{
    // release the SKScene here....
}];
ldindu
  • 3,613
  • 1
  • 17
  • 22