This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 25223 - IDB exposes GC behavior
Summary: IDB exposes GC behavior
Status: RESOLVED MOVED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: Indexed Database API (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal
Target Milestone: ---
Assignee: This bug has no owner yet - up for the taking
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-01 20:39 UTC by Olli Pettay
Modified: 2015-08-10 20:01 UTC (History)
5 users (show)

See Also:


Attachments

Comment 1 Joshua Bell 2014-04-02 19:06:19 UTC
Current spec text:

"The connection can be closed through several means. If the connection is GCed or execution context where the connection is created is destroyed (for example due to the user navigating away from that page), the connection is closed. The connection can also be closed explicitly using the steps for closing a database connection."

So, obviously, the spec shouldn't reference GC. It would capture the intent to say something like:

"If the connection object can no longer be used (for example, the user has navigated away from the page, or no references to the connection remain), the connection may be closed."

The more fundamental issue is that script can tell if GC has happened, e.g.

db = indexedDB.open('db', 1);
indexedDB.open('db', 2).onsuccess = function() { alert('GC happened'); };
db = null;

... which would preclude the use of the API in this fashion in e.g. a hypothetical environment with infinite memory.

I think that ship has already sailed with connection-type resources. For example, with Web Sockets - open two sockets to a server, drop the reference to the first, and when the server detects that the first is unusable it can signal the second. Just riffing, though.
Comment 2 Joshua Bell 2014-04-03 18:22:32 UTC
We should check the IE behavior here.
Comment 3 Joshua Bell 2014-09-29 20:45:43 UTC
I noticed that XHR deals with this explicitly:

https://xhr.spec.whatwg.org/#garbage-collection

"An XMLHttpRequest object must not be garbage collected if..."

Chromium doesn't allow GC unless closePending or it has no event listeners. I believe FF does something similar (or maybe never GCs open databases?)

So we could add wording such as:

"An IDBDatabase object must not be garbage collected if its closePending flag is false and it has one or more event listeners registers whose type is one of abort, error, and versionchange."
Comment 4 Jonas Sicking (Not reading bugmail) 2014-11-12 20:03:57 UTC
I agree that it's unfortunate to expose GC behavior here. But I don't see any alternative solution.

The only option I could think of would be to never close databases unless the .close() function is explicitly called. It's not clear that that's web compatible at this point though.

So let's not hold up the v1 spec for this at the very least.
Comment 5 Anne 2014-11-12 20:09:52 UTC
I don't understand. What about addressing comment 3 at least?
Comment 6 Jonas Sicking (Not reading bugmail) 2014-11-13 01:09:03 UTC
How is that different from the option I mentioned in comment 4?
Comment 7 Joshua Bell 2015-01-13 23:49:19 UTC
I added some blather similar to comment #3 into:

https://github.com/w3c/IndexedDB/commit/bdfc9964855d0ad650ade6da3ed0dd9b43b69d6a

... but I welcome more refinement. Leaving this open until we really nail down how to describe this.
Comment 8 Joshua Bell 2015-08-10 20:01:57 UTC
Moved to https://github.com/w3c/IndexedDB/issues/29