SpriteKit Memory Leak issue using Physics


Memory

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

Love computer programming and write occasional blog post. In my early career I worked mostly on web based application and since 2011, I exclusively working on iPhone and android applications. I work at home, father of a nice kid and husband of a beautiful wife. [My Business | Twitter | Linkedin]

You may also like

5 Comments

  • 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.

      [pre]
      @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);
      }
      [/pre]

  • Rik
    April 1, 2016 at 5:21 pm

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

Comments are closed here.

About Me

Hi I am Mahmud Ahsan. I Love computer programming and write occasional blog post. In my early career I worked mostly on web based application and since 2011, I exclusively working on iPhone and android applications. I work at home, father of a nice kid and husband of a beautiful wife. [My Business | Twitter | Linkedin]

Twitter Feed

Fanpage