crashes with stack overflow on repeated invocation

When repeatedly loading midi file, a stack overflow occurs:

stack overflow at Core/minilua/lapi.c:510
stack traceback:
	[C]: in ?

This code survives for about 10 frames on simulator; fewer on device:

local playdate <const> = playdate

function playdate.update()
    print("creating sequence")"songs/Rollinginthedeep.mid")

Minimal sample (code + pdx) (34.4 KB)

Looks like it's this bug: How to free up memory from a sound.track? Though I'm not sure why it manifests as a stack overflow. It's an out of memory problem, anyway, and that can have weird side effects when not handled properly.

Yeah, its sure seems to be, when I disable the memory limit in the simulator, the script keeps running and the simulator's memory usage keeps growing fast.

The mentioned workaround, If I understood correctly, doesn't work however:

local playdate <const> = playdate

function playdate.update()
    print("creating sequence")
    local sequence ="songs/Rollinginthedeep.mid")
    for i = 1, sequence:getTrackCount() do
    print("GC", collectgarbage("count")) 

prints 91.4024 on every iteration, but simulator still crashes when hitting the memory limit

That workaround isn't perfect--clearing notes frees the event list memory but the track itself is still leaking, possibly including controller messages which could take up a fair bit of memory. Hopefully we can get that fix out soon. Until then, caching the loaded sequences is probably the best workaround.