Android WebView - JavaScript memory leak

I have a problem with Javascript in WebView (enabled with webview.getSettings (). SetJavascriptEnabled (true);) HTML pages with embedded Javascript load and display correctly, however what I do constantly refreshes the screen every 10 or 30 seconds. When I enter the shell of my test device (MK808 mini-TV), I use "dumpsys meminfo" to see the process memory. Displaying the memory of my application process every 5 seconds, I see that whenever the page is refreshed, the memory usage of the application increases by several (4-10) megabytes. This continues for approximately 30 minutes or so until the application terminates with a Fatal Signal 11 error in WebViewCoreThread without a stack trace.

Constant increase in memory (started at about 15,000 KB):

enter image description here


None of these problems or memory errors occur when javascript is NOT enabled.

I clear Cache (true) and freeMemory (), as well as every other database, and clear the cache every time before updating.

I also tried to destroy WebView after each update and creating a completely new, to no avail.

I can easily redo this problem by simply creating a new application project and doing a webview that reloads based on the time it takes to control the handler. It seems like this should be a widespread problem, but I can't find anything on this. Could this be my device?

Thanks in advance for your help, I will be happy to add additional information as necessary!

+4
source share
1 answer

try adding this as well:

//Injects the supplied Java object into this WebView. The object is injected into the //JavaScript context of the main frame, using the supplied name. This allows the //Java object public methods to be accessed from JavaScript. WebView.addJavascriptInterface(new JavaScriptInterface(this), "Android"); 
0
source

Source: https://habr.com/ru/post/1488585/


All Articles