Some advice tracking down memory leaks

Hi,

I've been selling my game on itch.io for a couple of days now and some, but not all, players have spotted some strange behaviour on the device. It sounds like the sort of thing that would happen if the game was struggling to keep up a decent fps.

I'm worried that the game might have a severe memory leak, or that other games on the devices showing these issues do and it's affecting mine. I've got a couple of questions about testing for memory leaks in the simulator and about memory on the PlayDate in general.

  1. Can memory leaks only affect the game currently playing or can a game quit in such a way that it hasn't freed up all the memory that it's using? Will other games opened afterwards potentially suffer?

  2. Is the malloc log a good tool for checking for memory leaks? I leave it on and play 10 or so levels to see if it chows down on the heap size, but as far as I can tell heap usage trickles upwards until garbage collection is triggered and it goes down to a normal level, so it all seems reasonably stable.

  3. Some users appear to be leaving their devices on all the time and never turning it off. Is this advisable, doesn't practically everything leak memory? Even if there isn't a leak won't memory fragmentation result in allocated memory blocks getting split over more and more chunks, resulting in a performance hit, if nothing else?

Sorry if some of these questions are a bit silly. I remember (vaguely) waaay back in the day working on pre-iPhone devices. How the ram memory was handled was always a big worry.

1 Like
  1. The device is rebooted after a you choose home. So memory leak is contained to the currently running game.

  2. Not sure as I don't use C. But you can use the device view in Simulator to see live memory usage reporting from device.

  3. The device cannot be switched off. Also, see 1.

Interestingly, this old thread of mine was just bumped: Tracking memory usage throughout your game

ps: I had a memory leak using drawTextAligned in Lua, which was not triggering the garbage collector in scenes with little going on.

1 Like
  1. @matt's answer is correct; games can't interfere with each other like this.
  2. Yes, you can use it to inspect the heap of Lua games as well as C games, and with Lua you'll see the effect of the garbage collector. In a C game that uses manual memory management, you'll see different usage patterns.
  3. It's fine. Games have their execution paused while the Playdate is locked, so even if there's a memory leak, it won't get worse. "Practically everything" should not leak or fragment memory, unless there's a serious bug (which is certainly possible; please report if you're seeing this!).

The questions aren't silly, especially because other developers may have them as well. Thanks for asking them.

1 Like

Thanks all. I guess things have come a long way since I wrote games for pre-smartphone Nokias which only had 96Kb ram !

My biggest takeaway is that in-game leaks are always possible, not always logical, and can be tough sometimes to track down. However it looks like if any of the issues some of my players are seeing on device are caused by low memory hitting performance, then it's only my own code to blame.

I now think I have a better idea of how to go looking for memory leaks. Thanks ! :slight_smile:

Memory leaks when using SDK functions are possible.

I remember seeing a previous thread about that. Is there a list of SDK functions to watch out for anywhere?

No, if they happen it's likely a bug.