diff options
author | Leith Bade <leith@mapbox.com> | 2015-09-17 17:34:13 -0700 |
---|---|---|
committer | Leith Bade <leith@mapbox.com> | 2015-09-23 15:05:34 +1000 |
commit | 19e7d154bb540302339eb984f5350c20e9001020 (patch) | |
tree | 058028425cefb37ad5e828c89d078dd7ea0780ee /android | |
parent | 6e55dd575e481cb2b71e6dceac7739f0935e572b (diff) | |
download | qtlocation-mapboxgl-19e7d154bb540302339eb984f5350c20e9001020.tar.gz |
Improve handling of cancelled HTTP requests
Fix a memory leak of NativeMapView Java object
Diffstat (limited to 'android')
-rw-r--r-- | android/cpp/native_map_view.cpp | 4 | ||||
-rw-r--r-- | android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/http/HTTPContext.java | 4 |
2 files changed, 6 insertions, 2 deletions
diff --git a/android/cpp/native_map_view.cpp b/android/cpp/native_map_view.cpp index 02228d85b6..6c1cd87bb2 100644 --- a/android/cpp/native_map_view.cpp +++ b/android/cpp/native_map_view.cpp @@ -73,7 +73,7 @@ NativeMapView::NativeMapView(JNIEnv *env, jobject obj_, float pixelRatio_, int a return; } - obj = env->NewGlobalRef(obj_); + obj = env->NewWeakGlobalRef(obj_); if (obj == nullptr) { env->ExceptionDescribe(); return; @@ -93,7 +93,7 @@ NativeMapView::~NativeMapView() { JNIEnv *env = nullptr; ret = vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6); if (ret == JNI_OK) { - env->DeleteGlobalRef(obj); + env->DeleteWeakGlobalRef(obj); } else { mbgl::Log::Error(mbgl::Event::JNI, "GetEnv() failed with %i", ret); throw new std::runtime_error("GetEnv() failed"); diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/http/HTTPContext.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/http/HTTPContext.java index 4558bbfe34..775daaafdd 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/http/HTTPContext.java +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/http/HTTPContext.java @@ -20,6 +20,7 @@ class HTTPContext { private static final int CONNECTION_ERROR = 0; private static final int TEMPORARY_ERROR = 1; private static final int PERMANENT_ERROR = 2; + private static final int CANCELED_ERROR = 3; private static HTTPContext mInstance = null; @@ -78,7 +79,10 @@ class HTTPContext { type = CONNECTION_ERROR; } else if ((e instanceof InterruptedIOException)) { type = TEMPORARY_ERROR; + } else if (mCall.isCanceled()) { + type = CANCELED_ERROR; } + nativeOnFailure(mNativePtr, type, e.getMessage()); } |