www586089 opened a new issue, #1641:
URL: https://github.com/apache/cordova-android/issues/1641

   In CordovaWebViewImpl.java, there is a code snippet:
   
   {
           LOG.d(TAG, ">>> loadUrl(" + url + ")");
           if (url.equals("about:blank") || url.startsWith("javascript:")) {
               engine.loadUrl(url, false);
               return;
           }
   
           recreatePlugins = recreatePlugins || (loadedUrl == null);
   
           if (recreatePlugins) {
               // Don't re-initialize on first load.
               if (loadedUrl != null) {
                   appPlugin = null;
                   pluginManager.init();
               }
               loadedUrl = url;
           }
   
           // Create a timeout timer for loadUrl
           final int currentLoadUrlTimeout = loadUrlTimeout;
           final int loadUrlTimeoutValue = 
preferences.getInteger("LoadUrlTimeoutValue", 20000);
   
           // Timeout error method
           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);
               }
           };
   
           // 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);
                   }
               }
           };
   
           final boolean _recreatePlugins = recreatePlugins;
           cordova.getActivity().runOnUiThread(new Runnable() {
               public void run() {
                   if (loadUrlTimeoutValue > 0) {
                       cordova.getThreadPool().execute(timeoutCheck);
                   }
                   engine.loadUrl(url, _recreatePlugins);
               }
           });
       }
   
    cordova.getThreadPool().execute(timeoutCheck);  this line code just execute 
the timeoutCheck in a seperate thread(in thread pool), and in timeoutCheck will 
wait 20s, then check if timeout happen, if this happen do loadError Runnable in 
ui thead.
   my question is if run timeoutCheck in a specific thread and wait 20s, then 
user finish the webview container activity(less than 20s),  memory leak will 
happen. because the thread is wating, and hold some resource. and this action 
seem waste resource(hold a thread). I want to know why do like this and What 
are the considerations. (if post a delay message (20s), then do the check will 
more good ? or any way to avoid the memory leak).
   
   and there is a code snippet(the same question as before)
   
               // Make app visible after 2 sec in case there was a JS error and 
Cordova JS never initialized correctly
               if (engine.getView().getVisibility() != View.VISIBLE) {
                   Thread t = new Thread(new Runnable() {
                       public void run() {
                           try {
                               Thread.sleep(2000);
                               cordova.getActivity().runOnUiThread(new 
Runnable() {
                                   public void run() {
                                       pluginManager.postMessage("spinner", 
"stop");
                                   }
                               });
                           } catch (InterruptedException e) {
                           }
                       }
                   });
                   t.start();
               }
   


-- 
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.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

Reply via email to