tracker top-level property

DatabaseTracker tracker

Copied from moor This entire file is an elaborate hack to workaround https://github.com/simolus3/moor/issues/835.

Users were running into database deadlocks after (stateless) hot restarts in Flutter when they use transactions. The problem is that we don't have a chance to call sqlite3_close before a Dart VM restart, the Dart object is just gone without a trace. This means that we're leaking sqlite3 database connections on restarts. Even worse, those connections might have a lock on the database, for instance if they just started a transaction.

Our solution is to store open sqlite3 database connections in an in-memory sqlite database which can survive restarts! For now, we keep track of the pointer of an sqlite3 database handle in that database. At an early stage of their main() method, users can now use VmDatabase.closeExistingInstances() to release those resources.

Implementation

DatabaseTracker get tracker => _tracker ??= DatabaseTracker();