Skip to content

Commit

Permalink
Add canaryleak to detect memory leaks
Browse files Browse the repository at this point in the history
unregister local broadcast receiver in GsrReservationsFragment when fragment is destroyed to prevent memory leak. TODO: remove LocalBroadcastManager entirely because that shit deprecated.

remove LocalBroadCastManager from HomeFragment since it is unused (and was causing memory leaks)
  • Loading branch information
meiron03 committed Feb 12, 2024
1 parent ce424c8 commit 6bed148
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 18 deletions.
2 changes: 2 additions & 0 deletions PennMobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ android {
}

dependencies {
debugImplementation 'com.squareup.leakcanary:leakcanary-android:3.0-alpha-1'

implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation(platform("com.google.firebase:firebase-bom:31.5.0"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,8 @@ class GsrReservationsFragment : Fragment() {
getReservations()
}
}

override fun onDestroy() {
super.onDestroy()
LocalBroadcastManager.getInstance(mActivity).unregisterReceiver(broadcastReceiver);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package com.pennapps.labs.pennmobile

import android.content.*
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.Bundle
import android.os.Handler
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -17,7 +12,6 @@ import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.pennapps.labs.pennmobile.adapters.HomeAdapter
Expand Down Expand Up @@ -47,10 +41,6 @@ class HomeFragment : Fragment() {

mActivity = activity as MainActivity
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mActivity)

LocalBroadcastManager
.getInstance(mActivity)
.registerReceiver(broadcastReceiver, IntentFilter("refresh"))
}

override fun onCreateView(
Expand Down Expand Up @@ -188,13 +178,6 @@ class HomeFragment : Fragment() {
}
}


private val broadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
getHomePage()
}
}

override fun onResume() {
super.onResume()
mActivity.removeTabs()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ fun isOnline(context: Context?): Boolean {
return false
}


/** Shows an error sneaker given a view group with an optional retry function */
fun ViewGroup.showSneakerToast(message: String, doOnRetry: (() -> Unit)?, sneakerColor: Int) {
val sneaker = Sneaker.with(this)
Expand Down

0 comments on commit 6bed148

Please sign in to comment.