Does Component.detach() get invoked on Application close?

I have a Vaadin
Component
that registers a listener with some internal system resource inside the
attach()
method, and the de-registers the listener inside its
detach()
method.

If the Vaadin application somehow closes but this listener is never unregistered, then there will be a serious memory leak.

So I want to ensure that this doesn’t happen… which requires verifying the following:


  • Application.close()
    is always invoked when the servlet session is closed or expires
  • All
    Component
    s are
    detach()
    'd whenever an
    Application
    is closed

Are both of these statements true? I’m pretty sure about the first, but not so sure about the second.

Thanks.

Hi,

Yes

No

The servlet container you are running the application in will take care of notifying Vaadin when the session expires or ends in another way and at that point Application.close() will be called. As you can see from the Application.close() method it does not do very much. If you want detach to be called or any other cleanup to be done, you should override close(). In other words, Component.detach() is called when the component is removed from the component hierarchy in the application, not when the whole application is closed.

Thanks Artur.