mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-01 14:32:54 +01:00
Bangle.js: fix memory leak from HTTP requests
Every call to Volley.newRequestQueue() creates a new global thread pool, which isn't automatically cleaned up once the request completes. With this commit we create a RequestQueue around on first use, and reuse it for subsequent requests.
This commit is contained in:
parent
0c52f3d3da
commit
7e1685f5f9
@ -160,6 +160,9 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
// this stores the globalUartReceiver (for uart.tx intents)
|
||||
private BroadcastReceiver globalUartReceiver = null;
|
||||
|
||||
// used to make HTTP requests and handle responses
|
||||
private RequestQueue requestQueue = null;
|
||||
|
||||
/// Maximum amount of characters to store in receiveHistory
|
||||
public static final int MAX_RECEIVE_HISTORY_CHARS = 100000;
|
||||
/// Used to avoid spamming logs with ACTION_DEVICE_CHANGED messages
|
||||
@ -184,6 +187,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
super.dispose();
|
||||
stopGlobalUartReceiver();
|
||||
stopLocationUpdate();
|
||||
stopRequestQueue();
|
||||
}
|
||||
|
||||
private void stopGlobalUartReceiver(){
|
||||
@ -199,6 +203,19 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
gpsUpdateSetup = false;
|
||||
}
|
||||
|
||||
private void stopRequestQueue() {
|
||||
if (requestQueue != null) {
|
||||
requestQueue.stop();
|
||||
}
|
||||
}
|
||||
|
||||
private RequestQueue getRequestQueue() {
|
||||
if (requestQueue == null) {
|
||||
requestQueue = Volley.newRequestQueue(getContext());
|
||||
}
|
||||
return requestQueue;
|
||||
}
|
||||
|
||||
private void addReceiveHistory(String s) {
|
||||
receiveHistory += s;
|
||||
if (receiveHistory.length() > MAX_RECEIVE_HISTORY_CHARS)
|
||||
@ -598,7 +615,6 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
final String id = _id;
|
||||
|
||||
if (BuildConfig.INTERNET_ACCESS && devicePrefs.getBoolean(PREF_DEVICE_INTERNET_ACCESS, false)) {
|
||||
RequestQueue queue = Volley.newRequestQueue(getContext());
|
||||
String url = json.getString("url");
|
||||
|
||||
int method = Request.Method.GET;
|
||||
@ -691,6 +707,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
return h;
|
||||
}
|
||||
};
|
||||
RequestQueue queue = getRequestQueue();
|
||||
queue.add(stringRequest);
|
||||
} else {
|
||||
if (BuildConfig.INTERNET_ACCESS)
|
||||
|
Loading…
Reference in New Issue
Block a user