Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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):

  • Why does an empty database take megabytes of space
  • Does an empty field take up space in a database
  • IndexedDB deleteDatabase does not reset version
  • I seem to be getting a dirty read from an IndexedDB index. Is this possible?

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

like image 835
agryson Avatar asked Apr 05 '13 19:04

agryson


2 Answers

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?

like image 107
dgrogan Avatar answered Sep 28 '22 15:09

dgrogan


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.

like image 35
Kyaw Tun Avatar answered Sep 28 '22 15:09

Kyaw Tun