BeforeCompile & AfterCompile
Yes @TomTom, you’re 100% right. Although the GC would eventually get rid of even an interface guard the risk is that in the meantime, before being destructed, events would fire who knows where and when. Guarding passive data is one thing, but not unregistering delegates before they become inaccessible can end up in disaster.
I think there’s only one way to deal with this in a safe way in the Script component, and that is if @DavidRutten intoduces a BeforeCompile method (or event) and of course, an AfterCompile method (or event) on the Script_Instance class (the GH_Component can’t be overridden in this context anyway).
And as we have seen, the existing methods BeforeRunScript and AfterRunScript doesn’t help becaue it’s not related to neither mouse events nor to the compile command and so any delegates becomes inaccessible before having a chance to clean up any eventhandlers.
Being able to set up delegates/event subscribers is a crucial step in modern development. Prototyping with the script components is also extremely useful an efficient, so I can’t think of a good reason not to introduce those two methods (or hooks). Even if adding event hooks also on the GH_Component for this end, one would still need the extra Pre-Post-methods on the ScriptComponent in order to capture the case in which compiling renders any old event subscribers inaccessible.
I really think that the script component should become a first class member in the development tool box of grasshopper. Only the editor can remain simpler for simplicity’s sake.