Is there a deconstructor or disconnect capability, especially for JavaScript code?

Sonoran Music Devices's icon

I would like to reset global variables due to this issue, and I would also like to reset my LiveAPI callback properties when a device is deleted or reinitialized.

Questions:

  1. Is there a way to fire JavaScript code, say, via a deconstructor or disconnect function when a device is deleted from a Live set?

  2. Is there a way to fire JavaScript code, say, via a deconstructor or disconnect function when a device is reinitialized by doing a Edit->Reinitialize?

I have read as much as I can, and I cannot see any good way.

There is the closebang object, but people have reported problems with that in M4L. IIRC, it fires too late.