breautek commented on issue #1641: URL: https://github.com/apache/cordova-android/issues/1641#issuecomment-1945344102
I still fail to understand exactly where the memory leak is. ```java final boolean _recreatePlugins = recreatePlugins; cordova.getActivity().runOnUiThread(new Runnable() { public void run() { if (loadUrlTimeoutValue > 0) { cordova.getThreadPool().execute(timeoutCheck); } engine.loadUrl(url, _recreatePlugins); } }); ``` here it runs on the UI thread, and asusme we do have a non-zero positive timeout, it will execute the `timeoutCheck` runnable on a thread, then proceed to load the url in the webview. So while the webview is loading, it will also run: ```java // Timeout timer method final Runnable timeoutCheck = new Runnable() { public void run() { try { synchronized (this) { wait(loadUrlTimeoutValue); } } catch (InterruptedException e) { e.printStackTrace(); } // If timeout, then stop loading and handle error if (loadUrlTimeout == currentLoadUrlTimeout) { cordova.getActivity().runOnUiThread(loadError); } } }; ``` Here, while the webview is loading, it does [wait](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) up to the timeout value in milliseconds. Then it proceeds to check if the timeout state is the same as when the timeout started, and if so run the loadError runnable. If the webview has finished loading either by error or by success, `loadUrlTimeout` is updated and thus won't match `currentLoadUrlTimeout`. There is no indefinite waiting and this method will exit eventually taking at most up to the timeout value. When the function does exit, it's resources will be freeable by the GC. Lastly if it did enter the loadError runnable, then it does: ```java final Runnable loadError = new Runnable() { public void run() { stopLoading(); LOG.e(TAG, "CordovaWebView: TIMEOUT ERROR!"); // Handle other errors by passing them to the webview in JS JSONObject data = new JSONObject(); try { data.put("errorCode", -6); data.put("description", "The connection to the server was unsuccessful."); data.put("url", url); } catch (JSONException e) { // Will never happen. } pluginManager.postMessage("onReceivedError", data); } }; ``` At which point, it stops loading, and creates an error object to pass to the plugins. Again no indefinite waiting here either. Can you identity precisely what is leaking memory? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org For additional commands, e-mail: issues-h...@cordova.apache.org