Detach do not fire after 3 heartbeats

Hi,

I have to perform some tasks after a Vaadin UI is unloaded, and I’m trying to implement it using the missing of 3 hearbeat feature described in:


link

but my problem is that the
detach()
metod it’s only fired after session timeout,
in no case after the 3 missing heartbeats
(I’ve defined a heartbeat period of 5 seconds and a session timeout of 60 seconds).

Any clue of where might be the problem?

I’m using Vaadin 7.0.7

Thanks in advance and regards,
Martin

Hi, inactive UIs are not actually removed via a timer mechanism; instead the cleanup is done whenever there’s a request from the client. So, if you open and close a UI, then do nothing, it won’t be detached until the session times out. However, if you wait for 15 seconds, then open a new UI, you should see the old UI getting removed.

We should probably clarify the wiki article a bit.

I’m currently having a quite similar problem where the heartbeat just seems to not do anything.

I’m using a Thread to update a label (Clock) which gets executed every minute. Also i’m using the Vaadin 7.1.0.beta1 polling to display the changes to the client.

My problem now is that after the browser window/tab gets closed the thread keeps running and is not getting closed even with heartbeat turned on. The results are memory leaks in the Tomcat.

Am i just missing something obvious or is there just no simple way of closing the thread when the browser closes. (I’m trying to avoid the javascript hack that was mentioned in another forum thread.)

Thanks in advance,
Marius

Actually, this is a very commom feature that is really needed in most of the web applications: do a clean up of resources when the user does a change of context, or simply, as commented before, closes the browser window.

Does not exist any mechanism in Vaadin to achieve this?

The only “solution” I came up with is to maintain the session active with a short heartbeat period (let’s say, 10 seconds), and a session timeout of 15 seconds. This way we can detect any of the scenarios described before after those 15 seconds with the
detach()
UI method.

But it should be desirable to be able to catch some
unload
event on the UI.

Could this be possible?

One “hacky” way i found was using a javascript event but it isn’t reliable and that’s why i want to avoid it if possible. …but here’s the link if you want to have a look at it:
https://vaadin.com/forum#!/thread/2518250

Indeed, browser close events are unreliable and this is why Vaadin 7 does not use them.

The current heartbeat mechanism, as I described, prevents active memory/resource leaks via cleaning up old UIs when new UIs are opened. If there are no new requests, stale UIs live until session expiration, but this should not be a critical issue in most cases as the resource usage does not accumulate.

There’s a ticket,
#11852
, about exposing a few cleanup methods to the public API so that custom cleanup mechanisms would be easier to implement.