How to free up memory from a sound.track?

Oops, there's a memory leak there. :frowning: The Lua destructor isn't cleaning up the track, so that's 2KB of note list memory lost each time. But noteTrack:clearNotes() should do what you want. One tiny implementation detail I notice there: clearNotes() frees the note storage every time, even though the initializer pre-allocates 2KB of storage. That means in your case it's freeing then reallocating the same memory every time. I should instead have clearNotes() shrink it to 2KB if it's bigger, otherwise do nothing but change the number of notes to 0. Nope, I'm wrong, the buffer isn't allocated until you add the first note.

1 Like