Need help figuring out how to cleanup a resource instantiated by the a configuration

Hello!

I have a configuration that creates a FileHandler , which is a Java object that needs a cleanup. Up until now, the cleanup was done when binding the configuration (audit-trail-plugin/AuditTrailPlugin.java at 3deeb49fa8c21a2c7ce3e651aebdcb196343e11c · jenkinsci/audit-trail-plugin · GitHub).
This used to work well when the configuration was modified from the UI, but it doesn’t work when the configuration is modified with Casc (eg a Casc reload). I tried to move the cleanup in the setter of the object that needs cleanup (audit-trail-plugin/AuditTrailPlugin.java at 3deeb49fa8c21a2c7ce3e651aebdcb196343e11c · jenkinsci/audit-trail-plugin · GitHub) BUT I noticed that Casc makes two passes on the configuration a check (dry run) and then the actual configure pass. In each of them it creates the configuration objects… and I don’t see a way of performing some cleanup on the object created by the check pass since it’s never actually configured.

I understand that maybe the method used to cleanup is maybe not the correct one but I couldn’t find another example of a plugin with the same need. I didn’t see any hooks either to be notified that the configuration was “unloaded” and do some cleanup.