I’m definitely learning the 1-3-3-3 move.
Is the suggestion here that there ought not to be a need for an explicit cleanup? If so, ignore the rest of this.
In the situation where you are opening a session, playing and then closing down it’s likely not an issue anyway but where we are developing or modifying stuff and bumping the app after each change it could be give odd behaviour? I queried an array for this app that was sending double midi notes and got back two IDs, and then the problem just went away after a couple of reloads. Obviously, to make this more fun it doesn’t seem to be deterministic, it’s not just accumulating objects, it seems to be some odd edge case. Or, as ypxkap says, there’s a solid chance it’s just that my code is just that bad. It is.
If a cleanup is a sensible thing then maybe we should make a little template? Or just make it clear what sort of stuff we should have an eye on putting away at close? Robotfunk's suggestion that it’s handlers makes sense. I’m planning to add something like this to the end of my current app:
function cleanup ()
print("Cleanup")
allnotesoff()
midi_out_device:cleanup ()
midi_out_device = nil
tr.cleanup()
tr = nil
print("Cleanup done")
end
The all notes off is likely not needed but I guess there’s a race condition where it could be useful? I just pinched the :cleanup() method from docs, I have no idea if it’s doing anything good. I presume that simply setting the reference to a handler to nil doesn’t kill the thread, there’s no way it would know that? So, are the nil steps a waste of lines?
In this tr is a reference to a trigger monitor that I’ve posted in another thread. I guess I’ll need to end the polling in that? Something like:
function tr.cleanup()
p_amp_in:cleanup()
p_amp_in = nil
end
It’s a really tiny amount of code to stick into objects if it’s helpful, I guess I’m just trying to get a sense of how to do this right.