Reputation: 339
I am programming a game using Xcode and test it on the iOS Simulator, using the Sprite Kit.
The SKEmitterNode
I am using seems to cause a memory leak; when the game is running, each time SKEmitterNode
is put on the screen (when drawing an 'explosion'), under the "Show the Debug Navigator" on left, the Memory increases without bound.
Does anyone have a solution to this problem?
The code below is all in MYScene.m
.
My SKEmitterNode is called _EmitterShatterApart
which is an explosion called "ShatterApart.sks". _PositionObject
is an SKSpriteNode that is the object that is exploding. _bgLayer
is the background layer.
@implementation MyScene
{
SKEmitterNode *_EmitterShatterApart;
...
}
-(void)MatchIncorrect
{
...
_EmitterShatterApart = [NSKeyedUnarchiver unarchiveObjectWithFile: [[NSBundle mainBundle] pathForResource:@"ShatterApart" ofType:@"sks"]];
_EmitterShatterApart.position = _PositionsObject.position;
if (!_EmitterShatterApart.parent) {
//[self.particleLayerNode addChild:_EmitterShatterApart];
[_bgLayer addChild:_EmitterShatterApart];
_EmitterShatterApart.userInteractionEnabled=FALSE;
[_EmitterShatterApart resetSimulation];
}
}
Upvotes: 0
Views: 307
Reputation: 69027
Before adding a new emitter, you should remove the old one from the scene. Try with:
-(void)MatchIncorrect
{
...
[_EmitterShatterApart removeFromParent];
_EmitterShatterApart = [NSKeyedUnarchiver unarchiveObjectWithFile: [[NSBundle mainBundle] pathForResource:@"ShatterApart" ofType:@"sks"]];
...
If you do not do that, then you go on adding emitters to your scene, hence occupying memory without ever releasing it.
Upvotes: 1