Skip to content

Commit

Permalink
Fix for a memory leak, Leak Canary update (#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
vbuberen authored Oct 2, 2020
1 parent a3dbba9 commit 2f9c21a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 2f9c21a

Please sign in to comment.