agryson
agryson

Reputation: 297

Why does empty IndexedDB still take up space?

I'm using an IndexedDB for saving game data in Chrome.

An average game is about 4MB. After saving a few games, and then deleting them, the dev console's 'Resources' tab shows that my indexedDB is empty, as expected, but if I go to content settings, "Cookies and site data" it's showing me roughly 12MB as the indexedDB size on disk.

This is a after a refresh and even a restart of Chrome. The following is my code for deletion and I'm getting success when I delete and a query for the old data returns nothing, as expected.

database.indexedDB.deleteGame = function(nameIn){
    var db = database.indexedDB.db;
    var trans = db.transaction(["saves"], "readwrite");
    var store = trans.objectStore("saves");
    var wipeSlate = store.delete(nameIn);
    wipeSlate.onsuccess = function(e) {
        console.log("Old game wiped");
    };
    wipeSlate.onerror = function(e) {
        console.log("I don't think the old game existed..." + e);
    };
};

I've checked the following questions (and search results aren't showing anything too promising either):

But none of them deal with my question, any and all help very much appreciated.

Upvotes: 5

Views: 2956

Answers (2)

dgrogan
dgrogan

Reputation: 2720

Chrome doesn't immediately delete the data from disk, it is just marked deleted. If you write ~4 more megabytes to IndexedDB, LevelDB will do a compaction and the files containing the old entries will be deleted.

Chrome has no 50mb limit and will not ever ask for user permission for IndexedDB.

This question may be helpful. What are the storage limits for the Indexed DB on Google's Chrome browser?

Upvotes: 5

Kyaw Tun
Kyaw Tun

Reputation: 13131

Why are you worrying?

OS and Browser may take holistic approach to optimize user experience. Storage is one of them. In most situation, rather than deleting, marked them as deleted are more efficient.

Upvotes: 0

Related Questions