You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 13, 2019. It is now read-only.
Instantiation of WifiManager should use Application level Context instead of Activity level in NetworkEvents.java. Otherwise it will occur leak in WifiManager. The reference tree was attached below from leakcanary. This leak was reported in Issue 43945 from android issues.
public void register() {
registerNetworkConnectionChangeReceiver();
registerInternetConnectionChangeReceiver();
if (wifiAccessPointsScanEnabled) {
registerWifiSignalStrengthChangeReceiver();
// start WiFi scan in order to refresh access point list
// if this won't be called WifiSignalStrengthChanged may never occur
- WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);+ WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
wifiManager.startScan();
}
}
There was an odd behave about those leaks. Because WifiManager and ConnectivityManager were created in so many different places in your codebase. Why just has these two places leak?
Looking forward to your reply. Thanks in advance. :)
The text was updated successfully, but these errors were encountered:
Thank you for your work and investigating this issue!
As you can see, constructor of NetworkEvents class accepts Context as a parameter, so you can pass Application Context instead of Activity context inside your app. There's no need to update library.
I'll take a closer look at it later and read note on Google issue tracker carefully to analyze this problem better.
Nevertheless, we can update sample apps in the repository as well as documentation and add appropriate note about this issue in README.md file
pwittchen
changed the title
Memory leak
Memory leak in WiFiManager from Android SDK
Jan 8, 2016
WifiManager
should useApplication
level Context instead ofActivity
level inNetworkEvents.java
. Otherwise it will occur leak inWifiManager
. The reference tree was attached below from leakcanary. This leak was reported in Issue 43945 from android issues.Fix code in
NetworkEvents.java
:ConnectivityManager
can also leakActivity
.leakcanary dump heap info:
Fix code in
NetworkConnectionChangeReceiver
:WifiManager
andConnectivityManager
were created in so many different places in your codebase. Why just has these two places leak?Looking forward to your reply. Thanks in advance. :)
The text was updated successfully, but these errors were encountered: