SpriteKit Memory Leak issue using Physics


Recently I started to develop a physics based SpriteKit game and found weird issue of memory leak. I have been using XCode 7.2 while developing the game. I noticed my game taking memory though I didn’t add much sprite and I checked carefully of remove nodes from scene.

Memory Leak

After a lot of debugging and testing I found the reason. This is the physics drawing code by Apple which create memory leak. So if you face this issue while developing your game, either make it false or remove the line together.

skView.showsPhysics = true //create continuous memory leak

Though we don’t show physics in release mode, but still if you don’t know the reason of memory leak it will waste your time.

mahmud ahsan

Computer programmer and hobbyist photographer from Bangladesh, lives in Malaysia. My [Business | Twitter | Linkedin | Instagram | Flickr | 500px]

You may also like


  • Sergio
    February 10, 2016 at 8:08 am

    I can’t tell how much you saved me with this post. Thank you so much!

    • mahmud ahsan
      mahmud ahsan
      February 10, 2016 at 12:51 pm

      Its my pleasure. Happy game development using spritekit

  • Ino
    February 25, 2016 at 11:06 am

    Hi Mahmud, I am having the ios9 issue “plugin com.apple.GameCenterUI.GameCenterMatchmakerExtension invalidated”. It has been a real pain for several months now. I saw on a stackoverflow post that you solved the issue by checking if archive file is nil. Can you post code on how you solved this issue? It would be greatly, greatly appreciated!

    • mahmud ahsan
      mahmud ahsan
      February 25, 2016 at 12:10 pm

      Well please see the following code. The problem in iOS 9.0, NSKeyedUnarchiver previously generate nullpointerexception but now they don’t. So I have to manually check whether its null or not, the try/catch block is not effective here. Thus it solved my issue.

      @try {
      NSDictionary *loadedDict = [NSKeyedUnarchiver unarchiveObjectWithData:data];

      if (loadedDict != nil){
      //game start here
      [self loadGameCanvasFrom1stPlayer: loadedDict];
      [self setupStringsWithOtherPlayerId:playerID];
      [self hidePopUpView];
      [self hideHud];

      return; //EXIT POINT
      @catch (NSException *exception) {
      //do nothing
      DLog(@”Special Exception: %@”, exception);

  • Rik
    April 1, 2016 at 5:21 pm

    I just discovered the same issue in 7.3.
    Has this been reported to apple ?