From 2f9c21aeeb49688a647c922dbef00cff61f8783a Mon Sep 17 00:00:00 2001 From: Volodymyr Buberenko Date: Fri, 2 Oct 2020 17:02:57 +0300 Subject: [PATCH] Fix for a memory leak, Leak Canary update (#465) --- build.gradle | 2 +- .../chucker/internal/data/repository/RepositoryProvider.kt | 4 ++-- .../chucker/internal/data/room/ChuckerDatabase.kt | 6 +++--- .../chuckerteam/chucker/internal/ui/BaseChuckerActivity.kt | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index a1e5a83e3..9edc1e22e 100644 --- a/build.gradle +++ b/build.gradle @@ -24,7 +24,7 @@ buildscript { dokkaVersion = '1.4.10' ktLintVersion = '0.39.0' ktLintGradleVersion = '9.4.0' - leakcanaryVersion = '2.4' + leakcanaryVersion = '2.5' // Testing androidxTestCoreVersion = '1.3.0' diff --git a/library/src/main/java/com/chuckerteam/chucker/internal/data/repository/RepositoryProvider.kt b/library/src/main/java/com/chuckerteam/chucker/internal/data/repository/RepositoryProvider.kt index 2862611d9..5c1fbc907 100644 --- a/library/src/main/java/com/chuckerteam/chucker/internal/data/repository/RepositoryProvider.kt +++ b/library/src/main/java/com/chuckerteam/chucker/internal/data/repository/RepositoryProvider.kt @@ -29,9 +29,9 @@ internal object RepositoryProvider { /** * Idempotent method. Must be called before accessing the repositories. */ - fun initialize(context: Context) { + fun initialize(applicationContext: Context) { if (transactionRepository == null || throwableRepository == null) { - val db = ChuckerDatabase.create(context) + val db = ChuckerDatabase.create(applicationContext) transactionRepository = HttpTransactionDatabaseRepository(db) throwableRepository = RecordedThrowableDatabaseRepository(db) } diff --git a/library/src/main/java/com/chuckerteam/chucker/internal/data/room/ChuckerDatabase.kt b/library/src/main/java/com/chuckerteam/chucker/internal/data/room/ChuckerDatabase.kt index 90ea366f3..1a57f0b8b 100644 --- a/library/src/main/java/com/chuckerteam/chucker/internal/data/room/ChuckerDatabase.kt +++ b/library/src/main/java/com/chuckerteam/chucker/internal/data/room/ChuckerDatabase.kt @@ -17,11 +17,11 @@ internal abstract class ChuckerDatabase : RoomDatabase() { private const val OLD_DB_NAME = "chuck.db" private const val DB_NAME = "chucker.db" - fun create(context: Context): ChuckerDatabase { + fun create(applicationContext: Context): ChuckerDatabase { // We eventually delete the old DB if a previous version of Chuck/Chucker was used. - context.getDatabasePath(OLD_DB_NAME).delete() + applicationContext.getDatabasePath(OLD_DB_NAME).delete() - return Room.databaseBuilder(context, ChuckerDatabase::class.java, DB_NAME) + return Room.databaseBuilder(applicationContext, ChuckerDatabase::class.java, DB_NAME) .fallbackToDestructiveMigration() .build() } diff --git a/library/src/main/java/com/chuckerteam/chucker/internal/ui/BaseChuckerActivity.kt b/library/src/main/java/com/chuckerteam/chucker/internal/ui/BaseChuckerActivity.kt index bc22e256d..3f785f79b 100644 --- a/library/src/main/java/com/chuckerteam/chucker/internal/ui/BaseChuckerActivity.kt +++ b/library/src/main/java/com/chuckerteam/chucker/internal/ui/BaseChuckerActivity.kt @@ -9,7 +9,7 @@ internal abstract class BaseChuckerActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - RepositoryProvider.initialize(this) + RepositoryProvider.initialize(applicationContext) } override fun onResume() {