Should GeneratedColumn and others be garbage collected? #2691
-
I'm running some tests in my app and trying to locate hard to find memory leaks. I notice that if I do an insert with Drift, some classes are added to the heap and never gc'd. So far, I've noticed these: GeneratedColumn: ~180 instances I notice that whether I run 50 inserts or 500, the relative number of instances stays the same, however, they are still never released. I also notice that when I start the app, connect to the db, but don't do any inserts, GeneratedColumn sits at around ~7 instances. Shouldn't all of these classes get gc'd once the operations are done, or when the next gc cycle hits? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Thanks for the report. Drift classes should absolutely be garbage collected when no longer used. The The |
Beta Was this translation helpful? Give feedback.
I just ran the example app from this repository and inspected the instance count from the DevTools memory inspector. It only uses about 10
DatabaseConnection
instances, but I think having a little more than that not necessarily unusual if the database is set up across isolates (e.g. withNativeDatabase.createInBackground
). Things likeLazyDatabase
also increment the number, but these are live objects that really are used.The example app contains functionality to restore databases from a backup, which is a good indicator for memory leaks since it completely re-opens the database. But trying that a few times and looking at the live instance count, I couldn't find anything suspicious.