App cleanup?

In fixing/making/breaking I’m often making small changes and then hitting the play button to relaunch the edited app and I’ve noticed an odd thing. Sometimes it looks like several instances of the app are being loaded. I was ignoring the fact that sometimes it registers as having loaded preset Y 4 times and then maybe only once in the morning but I just also had odd behaviour where I had 2 identical midi notes being triggered and then when I did a reset the behaviour just went away.
It made me wonder if there’s any possibility that somehow the objects are not being garbage collected and persist though a ‘press the play button’ type reload?
I’ve not seen any explicit cleanup in any of the apps I’ve dug through, do we need this, has anyone else noticed similar behaviour?

Oh yes in several scripts. I’m developing one and have not even started looking into this. I think it is mainly the callback handlers you make listen to events like MIDI notes or button presses that explicitly need to be cleared when stopping an app.

1 Like

i always have this script in my projects so i can type rerun() from maiden. i never have issues like you describe.

function rerun()

FYI this should be the same as pushing the PLAY button in the maiden UI


Thanks all!
I’m going to put a cleanup in and explicitly end the listeners.
Having that rerun code in can’t hurt, though hitting PLAY has been my usual way to do this.
Is there any debugging type routine that I ought to know about to spot this sort of stuff? I’m at the put-lots-of-print-statements-in level at the moment.

i am the type of user to never get beyond the “lots of print statements” level, probably hitting the save+run buttons close to 1000 times a session, 50%+ failing to fully load the script. i notice weird stuff like this too, but have always chalked it up to my code being just that bad. i will typically be able to restore expected behavior by browsing to a script i know is well designed/maintained and playing it from maiden and then going back to my WIP script. this works about 80% of the time, otherwise i will do a full restart of the norns. i used to use vim on norns to code and don’t recall this kind of thing happening in there—maybe a maiden->matron communication issue?

1 Like

wondering if anyone has the same issues by re-running using

K1 K3 K3 K3

(ie, reload same script from menu. i don’t know why i got into this habit)


woaaahhh this is awesome

1 Like

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 ()
  midi_out_device:cleanup ()
  midi_out_device = nil
  tr = nil
  print("Cleanup done")

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 = nil

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.

There is a cleanup function called, yes, clenaup() in the docs under basic script.

In some music it is somehow genre-typical to have this kind of a breakdown at the end of a song (feedbacks with guitar or whatever). Here’s an example from Rattus – those who grew up under the shadow of nuclear holocaust :radioactive::exploding_head: will be able to relate to the lyrics.

Maybe norns scripts too could do something like this on cleanup?

1 Like