Memory Leaks

This topic contains 6 replies, has 2 voices, and was last updated by  CartoonSmart 5 months, 2 weeks ago.

  • December 3, 2017 at 6:25 pm #176878

    I have my levels working properly. It seems the longer I play them, memory usage increases until the game locks up. I even created sub levels to reduce the number of nodes at anyone time. Is there any management I need to do on my side? Or is there a place in the code I can check for node removal and scene deletion…

  • December 3, 2017 at 7:55 pm #176879

    I found that adding the property PrefersOpenGL to YES in the info.plist file results is more even memory usage. Justin, thoughts?

  • December 4, 2017 at 12:16 pm #176905

    I’ve never set that property in the plist before. I’d assume if Apple thought it was best to include that, the Sprite Kit templates would have it in there already.

    So I wouldn’t include it unless you have a specific reason to.

  • December 4, 2017 at 12:45 pm #176906

    The increases in usage that is not released appears to be when entering portals that load a new scene file. The game eventually locks up. I am having trouble tracking this one down. When the property is set to NO, MetalKit is used and the leaking becomes more aggressive than when using OpenGL. I can’t have a game that locks up from extended play. Any ideas where to look in your experience? Thanks again for your patience…

  • December 4, 2017 at 1:07 pm #176907

    You could do some searching here….

    Memory management comes built into Sprite Kit. And Swift. We don’t have to retain / release stuff anymore. So Sprite Kit should automatically release any child on the outgoing scene. A few years back, I did notice when programming the Story Tellers Kit that memory could climb from scene to scene, so I added a cleanUpScene() function to that kit (and because I reuse a lot of code other kits got it too). So the RPG kit has it in there. It

    1. removes all actions on the main scene.
    2. iterates through all children and removes their actions
    3. clears all gesture recognizers (which is good to do anyway between scenes)

    On step 2 there, you could also include node.removeFromParent()

    for node in self.children {
               node.removeFromParent()  //add this

    Thats makes for a less smooth transition between scenes because the outgoing scene goes blank before leaving. So I don’t include that one line.

    Are you testing on that older iPad you have? You could do some device testing in the code and only run that line on that particular iPad model.

    Also I wouldn’t put it past Apple to introduce a problem that only affects older devices with iOS11. That gets talked about a lot on tech sites. I don’t think it’s a conspiracy (like some do), I just don’t think Apple spends as much time testing something like iOS11 on a 3 or 4 year old iPad then they do with whats current and upcoming. And in general, I don’t think Apple spends a lot of time programming Sprite Kit games to test on either. Developers are really the front line for figuring out what’s busted. I’ve filed plenty of bug reports that have been acted on by Apple. So they do listen to us.

  • December 4, 2017 at 2:28 pm #176913

    I added the code you suggested and it didn’t affect the game that I could tell; however, the leak continues when traveling back and forth between scenes. I am using my older iPad and will test with my iPhone7 Plus. I have emailed you an image of what happens when you go between screens…

    UPDATE: Same memory behavior with my iPhone 7 Plus.

  • December 4, 2017 at 3:00 pm #176916

    I’m not getting the same thing here on my iPad Pro. My memory goes back down.

    Sprite Kit Memory Usage

    You’ll always see a spike between scene transitions because both scene exist at once. Also worth nothing, a gradual increase of memory usage over time isn’t necessarily a leak, because as new assets are being introduced they are getting cached as well. SpriteKit is holding onto things like image atlases, so it can load them faster the next time they are requested. So as long as the memory stays in the green, I doubt Sprite Kit is going to force the cache to be dumped.

    The image you sent didn’t show the green to red meter, where is your iPad putting the meter at? I saw it peaked at 360mb, but considering the orange zone begins at 2gb, thats relatively low.

You must be logged in to reply to this topic.

Download the new CartoonSmart TV App - Tons of FREE and Premium Lessons

It's Free Right? Sure, I'll Get It!