samplePlayer sometimes leaks memory, sometimes not—with no change to game?

I’ve spent weeks (on and off for a year) trying to fix memory leak(s) that sometimes crash my game. The culprit is samplePlayers not releasing the memory they use—so small sounds leak a little, big ones leak a lot. I’m reading sounds from disk when needed (too much data to pre-load them all) using sound = snd.sampleplayer.new(filename). I keep re-using sound, and setting it to nil or :stop()-ing it first seems to make no difference.

But I realize now that Lua code changes that seemed to help are irrelevant: I’d see constant leaking, make a change and then see none... but it was coincidence. The SAME build leaks to a crash within minutes sometimes, runs fine indefinitely other times—when sitting idle without a user actually playing.

This is true in both the sim and on-device.

Sounds are played randomly, but I’ve saved logs of which sounds were playing and there’s no correlation: the same exact sound files will either leak or not.

But there is ONE pattern: once it starts leaking, relaunching the sim won’t help. It keeps leaking for hours, run after run. Then, randomly, it will STOP leaking! And eventually START leaking again—in the middle of a leak-free run.

It’s almost as though something external to the game—and surviving reboots—is putting it in “leak mode” or not. The mode comes and goes, but not often: either mode can last for hours. I’m not even sure which is more common! (I’ve tested less on-device, but that pattern seems to be true there as well.)

Is this likely to be an SDK issue I can’t address, or does this behavior suggest something more I could look at? I don’t want to report a bug that’s not one and waste Panic’s time.

Thanks in advance!

I’ve been unable to make a simple reproduction case, because the issue seems to happen—or not—regardless of what I do with my code. The moment the issue appears/disappears seems to be coincidental.

(This 2023 thread reports an ADPCM WAV leak (fixed?) but I see a leak with PCM too.)

1 Like