all: fix db memory leak

Fix an issue where the database instances would leak memory due to an
incorrect context use.
This commit is contained in:
Alexander Capehart 2023-01-29 19:22:31 -07:00
parent 2413edfd5e
commit 4012c35cf4
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
3 changed files with 6 additions and 2 deletions

View file

@ -187,7 +187,9 @@ private abstract class CacheDatabase : RoomDatabase() {
synchronized(this) {
val newInstance =
Room.databaseBuilder(
context, CacheDatabase::class.java, "auxio_metadata_cache.db")
context.applicationContext,
CacheDatabase::class.java,
"auxio_metadata_cache.db")
.fallbackToDestructiveMigration()
.fallbackToDestructiveMigrationFrom(0)
.fallbackToDestructiveMigrationOnDowngrade()

View file

@ -69,7 +69,7 @@ abstract class PersistenceDatabase : RoomDatabase() {
synchronized(this) {
val newInstance =
Room.databaseBuilder(
context,
context.applicationContext,
PersistenceDatabase::class.java,
"auxio_playback_persistence.db")
.fallbackToDestructiveMigration()

View file

@ -280,6 +280,7 @@ interface PlaybackStateManager {
*/
fun get(): PlaybackStateManager {
val currentInstance = INSTANCE
logD(currentInstance)
if (currentInstance != null) {
return currentInstance
@ -553,6 +554,7 @@ private class RealPlaybackStateManager : PlaybackStateManager {
// Internal player may have reloaded the media item, re-seek to the previous position
seekTo(savedState.positionMs)
}
isInitialized = true
}
// --- CALLBACKS ---