0

I am a beginner with Xcode's sprite-kit programming a game for the iPhone. I am having an issue with the SKEmitterNode. Specifically it looks like I have an unbounded memory leak every time the following SKEmitterNode is added even though I use the removeFromParent SKAction. Anyone have a solution to this? Thanks

SKEmitterNode *_EmitterShatterApart; 
...
-(void)ShatterApart
    {
    SKAction *fadeaway = [SKAction fadeOutWithDuration:0.5];
    SKAction *removeFromParent = [SKAction removeFromParent];
    _EmitterShatterApart = [NSKeyedUnarchiver unarchiveObjectWithFile: [[NSBundle mainBundle] pathForResource:@"ShatterApart" ofType:@"sks"]];
    _EmitterShatterApart.position = _NodePlayer.position;    
    if (!_EmitterShatterApart.parent) {
        [_bgLayer addChild:_EmitterShatterApart];
        _EmitterShatterApart.userInteractionEnabled=FALSE;
        [_EmitterShatterApart runAction: [SKAction sequence:@[fadeaway,removeFromParent]]];
    }
}
user3797886
  • 339
  • 1
  • 3
  • 16

1 Answers1

1

The _EmitterShatterApart will not be deallocated after you call removeFromParent action because you are keeping a strong reference to it in a static variable you defined here:

SKEmitterNode *_EmitterShatterApart; 
Rafał Sroka
  • 39,540
  • 23
  • 113
  • 143
  • Thanks reecon, could you advise me on how exactly I can fix the issue? Should I define _EmitterShatterApart differently? – user3797886 Jul 19 '14 at 22:27
  • Would be good to takes some time to learn what a strong reference is and get a basic understanding of how ARC (Automatic Reference Counting) works. It'll save you time and headaches now and later. – prototypical Jul 20 '14 at 23:26
  • Definitely you should do it. Such issues are sometimes hard to spot and can cause random low memory crashes. It will not take lots of time to learn and it's pretty easy. – Rafał Sroka Jul 21 '14 at 06:30