want to remove notifier on my tool window closing

Is there any way to intercept the event close of my tool window and invoke a function ?

Hm, I don’t think there is a direct way to receive such a notification.
When window looses the focus, app_resigned_active_observable is called - but this isn’t the same thing.

However, you could monitor the state of the dialog by attaching yourself to the app_idle_observable
(assuming here that ‘dialog’ is the name of the window you have created)

renoise.tool().app_idle_observable:add_notifier(function()  
  
 if dialog and not dialog.visible then  
 -- do something...  
 end  
  
end)  

Usually i just only use this approach, not even using the idle notifier. If i need to perform an action based on whether a dialog is visible or not, i just take care the dialog object is declared globally (thus existing when checking it out) and then simply perform the action on this very condition.

What should be the event, if no idle notifier is used ?

I mean, suppose I wish to remove all the attached notifiers with a certain dialog.
Where / when I should call this piece code?

  
if dialog and not dialog.visible then  
 -- do something...  
end