Chrome Auto Tab Discard

asked 2021-06-09 17:23:53 +0800

DerekW gravatar image DerekW

Chrome has a feature - automatic tab discard that reduces the memory load of open-but inactive-tabs, but it seems zk framework cannot destroy the desktop of discarded tab by chrome.

delete flag offensive retag edit

1 Reply

Sort by ยป oldest newest

answered 2021-06-10 19:24:52 +0800

MDuchemin gravatar image MDuchemin
1901 1 5
ZK Team

TL:DR : There are safety against memory leaks that could be caused by this, but this is still a fair point. If the desktop browsers are introducing mobile-browser-ish features like automatic unload, then more aggressive desktop lifecycles can be necessary.

There is an open feature in the ZK tracker that already consider implementing a watchdog which basically pings the client tabs every once in a while to check if they are still alive.

Big technical talk below:

This is a known blindspot in the beforeUnload visibilityState APIs

The situation is that visibilityState does too much, and beforeUnload does too little.

beforeUnload will not trigger in a number of scenerios:

Browser is terminated directly without having a chance to fullfill beforeUnload (closed from task manager, from app manager, OS failure, Power failure, network failure, unsupervised children left near a router, etc.). This may also happen in other cases such as browser can perform beforeUnload, but the request is intercepted before reaching the webserver (SSO session incorectly configured to catch zkau and expired, etc)

The alternative to beforeUnload is visibilityStates. For web applications, the Page Lifecycle API recommends treating "visibilityChange event with state "hidden" as end-of-session", due to this event always being available at some point before the page is terminated (regardless of the termination cause). That's fine and good for an application which only keep state as a far as showing you advertisement, but a ZK application usually has a complex state, and no one want their user to essentially do a forced refresh every time they click in a different browser tab to search a thing.

What does that means in ZK?

ZK uses the beforeUnload option, and assume that most pages will be able to perform beforeUnload and transmit a "desktop remove" command. Desktop is the name of the Server-side Java object representing the browser Tab, and maintaining its state. (This is the simple case, sometime there are multiple desktops, but the general idea is the same)

When a browser tab is unloaded (manually from the discards page, from the Chrome task manager with end-process, etc), it doesn't have the ability to call the beforeUnload function and send the desktop remove command.

In this state, the desktop (server-side object representing the tab) is "orphaned". The browser tab no longer exist, but the desktop still exists, and more importantly, has memory assigned to it.

Is that bad?

Bad: you got memory spent to maintain a tab that no longer exist.

Good: it's not permanent.

The hierarchy of objects for a ZK page is:

  1. Web Server session
  2. ZK Session (1 to 1 per webserver session)
  3. Desktop ( 1 to many per ZK session)

Desktop will still be purged in all of the following cases:

  • If the Webserver (or the ZK) session is destroyed, any associated desktop will also be destroyed. This happens automatically when the session reaches its timeout.
  • If the desktop itself reach its timeout, it will become available to be cleaned by the garbage collector
  • If the user keep opening tabs in the same session, they will eventually reach the max-desktop-per-session limit, at which point older desktops will be destroyed.

There are other more complex mechanisms and safety that makes permanent memory leaks unlikely, as long as the configuration is safe.

Now, with all of this said :D

The tracker entry linked above contain a github link to an experimental watchdog implementation. If you find that your memory load is non-manageable with session / desktop timeouts and expiration, I'd recommend trying this implementation.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools




Asked: 2021-06-09 17:23:53 +0800

Seen: 5 times

Last updated: Jun 10

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More