In Java Wicket 6, I'm trying to find out how to get notified in a Page or Component when that Page / component is no longer used.
The context is I have a configuration service that can have listeners added to it to notify when configuration has changed / reloaded.
Obviously, if a page/component is no longer needed then I should remove it as a listener from the service, but I can't find a way of being notified or that fact.
onRemove() doesn't cut it, as it doesn't appear to be called on the page or components in the page since I'm not explicitly REMOVING anything. I'm just letting pages/components drift away into the ether.
Any ideas on how I can clean up my resources to make sure my listener list / memory footprint doesn't balloon over a period of time?
My pages are stateful, btw (although I'm not sure they need to be atm). The Configuration Service is injected into a Page/Component via @SpringBean.
One possible way to propagate a configuration update it to have the page listen ONLY and then fire a Wicket event to contained components. This would cut down on the number of listeners to the Service, but this doesn't FEEL very nice if the components have a reference to the Configuration Service anyway to then be told by something else that it needs to reconfigure. Maybe.
Even so, with the above solution I'd still like to clear the Page from the listener list when no longer needed.
By using
@SpringBeanyou do not make a hard reference between the Page/Component and the real service instance!@SpringBeaninjects a (serializable) Proxy that has logic to lookup the Spring bean from Spring's ApplicationContext. So I think you have nothing to clean actually.