WatermelonDB icon indicating copy to clipboard operation
WatermelonDB copied to clipboard

How can I destroy the database and in-memory lokidb instance on web

Open KennanChan opened this issue 2 years ago • 3 comments

I am using watermelondb with lokidb on web. I create database shardings to minimize the data transfered and stored in a single pull phase. When I change from a database sharding "A" to a new database sharding "B", I am wondering how I can make sure to destroy the sharding "A" and its in-memory lokidb to avoid memory leak.

KennanChan avatar Apr 13 '22 15:04 KennanChan

I found an undocumented call:

database.adapter.underlyingAdapter?._driver?.loki?.close?.()

Is it safe to use? why not expose a close method?

KennanChan avatar Apr 13 '22 16:04 KennanChan

the loki.close() just ensure the lokidb do some necessary operations like saveing dirty records etc, which does not destroy the database. I do not find any useful method that lokidb exposed to destroy in-memory data it holds.

It seems I am left to rely on the main gc process to collect the unused lokidb.

Anyone has ideas?

KennanChan avatar Apr 13 '22 16:04 KennanChan

One thing to clarify is that what I mean "destroy" is not to destroy the database on indexedDB, but to destroy the database connnection and the in-memory database to free some memory, since my project is a mobile web page which will be running on some old devices

KennanChan avatar Apr 14 '22 03:04 KennanChan