0
이봐 최근에 내가 추가 한 누설 카나리아.누출 com.myapp.MainActivity 인스턴스 6.9MB 내 애플 리케이션과 내 <code>GPSTracker</code> 클래스에이 이상한 누출을 얻고로
누출 보고서 말한다 :
02-07 17:42:35.524 25788-26863/com.myapp D/LeakCanary: * com.myapp.MainActivity has leaked:
02-07 17:42:35.525 25788-26863/com.myapp D/LeakCanary: * GC ROOT android.location.LocationManager$ListenerTransport.this$0
02-07 17:42:35.525 25788-26863/com.myapp D/LeakCanary: * references android.location.LocationManager.mContext
02-07 17:42:35.525 25788-26863/com.myapp D/LeakCanary: * references android.app.ContextImpl.mOuterContext
02-07 17:42:35.525 25788-26863/com.myapp D/LeakCanary: * leaks com.myapp .MainActivity instance
02-07 17:42:35.525 25788-26863/com.myapp D/LeakCanary: * Retaining: 6.9 MB.
02-07 17:42:35.525 25788-26863/com.myapp D/LeakCanary: * Reference Key: d4781b46-49a2-426c-b2ba-15b9a1207dd6
02-07 17:42:35.525 25788-26863/com.myapp D/LeakCanary: * Device: LGE google Nexus 5 hammerhead
02-07 17:42:35.525 25788-26863/com.myapp D/LeakCanary: * Android Version: 6.0.1 API: 23 LeakCanary: 1.5 00f37f5
02-07 17:42:35.525 25788-26863/com.myapp D/LeakCanary: * Durations: watch=5106ms, gc=156ms, heap dump=5555ms, analysis=32364ms
02-07 17:42:35.525 25788-26863/com.myapp D/LeakCanary: * Instance of android.location.LocationManager$ListenerTransport
그리고 내 GPSTracker 클래스
public class GPSTracker implements LocationListener {
private Context context;
private boolean isGPSEnabled = false;
private boolean canGetLocation = false;
private Location location; // location
private double latitude; // latitude
private double longitude; // longitude
private final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 5; // 5 meters
private final long MIN_TIME_BW_UPDATES = 1500; // 15 sec
private LocationManager locationManager;
public GPSTracker(Context context) {
this.context = context;
getLocation();
}
public boolean getGpsStatus() {
isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
return isGPSEnabled;
}
public Location getLocation() {
try {
locationManager = (LocationManager) context.getSystemService(LOCATION_SERVICE);
isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
boolean isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGPSEnabled && !isNetworkEnabled) {
Log.i("No Network Provider", "No Network Provider Available");
} else {
this.canGetLocation = true;
if (isNetworkEnabled) {
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, GPSTracker.this);
if (locationManager != null) {
location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
Log.i("gps", "Location got from NETWORK");
Log.e("Current Location", "Lat : " + latitude + " Long : " + longitude);
}
}
} else {
if (location == null) {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, GPSTracker.this);
if (locationManager != null) {
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
Log.i("gps", "Location got from GPS");
Log.e("Current Location", "Lat : " + latitude + " Long : " + longitude);
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return location;
}
public double getLatitude() {
if (location != null) {
latitude = location.getLatitude();
}
return latitude;
}
public double getLongitude() {
if (location != null) {
longitude = location.getLongitude();
}
return longitude;
}
public boolean canGetLocation() {
return this.canGetLocation;
}
@Override
public void onLocationChanged(Location location) {
this.location = location;
try {
Log.e("GPS Status", "Lat : " + location.getLatitude() + " Long : " + location.getLatitude());
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
onLocationChanged(locationManager.getLastKnownLocation(provider));
locationManager.requestLocationUpdates(provider, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
protected void finalize() throws Throwable {
removeLocationListener();
super.finalize();
}
public void removeLocationListener() {
context=null;
locationManager.removeUpdates(GPSTracker.this);
locationManager=null;
location=null;
}
}
입니다 그리고 당신은 MainActivity
파괴 할 때 내가 removeUpdates에 시도 것을 알 수 있습니다. 그러나 여전히 동일한 누출이 반복적으로 발생하는 것은 변하지 않았습니다.
혼란스러워!
Tadda을! 그것은 나를 위해 일합니다! –