Imagine a situation where user works with some JSF page which makes use of a ViewScoped backing bean. In case of navigation to a different page within the application the custom destructor (i.e. @PreDestroy) of the bean will be called automatically. In case of the user closing a tab/window properly one can invoke a remote command at the server via AJAX in order to free the bean.
However, what if simply the power fails on the user side and PC is turned of instantly or the browser gets terminated improperly such that no JS code can be invoked. This implies that the bean will hang on the server side forever using its resources. How can such problem be solved?
One of the solutions I think of is to put a PrimeFaces poll element on the page which would "ping" the managed bean via remote command. If the bean notices a timeout then it will terminate itself freeing all resources. Is there any better solution for this problem? Thx.