Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8097373

WebView/Webkit memory leak leading to JVM crash



    • Subcomponent:


      There appears to be a memory leak when loading html content into the WebView that uses javascript. More specifically, when a new Array() is allocated within a function it seems that after that function terminates the memory allocated to that array is never reclaimed. It may be that this issue exists for non-array variables, however it is clearly more dramatic for arrays.

      Here is a sample application that can be used to demonstrate the leak. It is comprised of two files, a java file and an html file. To run this application, place both files in the same directory and execute the main in the java file.

      The application basically creates a number of text nodes based on the value in the text field "Number of text nodes to create" and then runs a function that parses the DOM and accumulates all text nodes into an array at the frequency supplied in the "Loop frequency in milliseconds" field. There are two buttons, one that uses a globally defined array which is re-populated each time the function is executed. The other button allocates a new Array each time the function is run and after removes all items and nulls the array.

      To observe the leak run the test and click the button "Start test with function local array" and watch the memory usage in the task manager. You will notice that the memory usage trends upwards. I discovered that by using a global array that the application does not leak under the same conditions, to see this run the test by clicking the button "Start test with global array".

      To be sure that this is not just an issue with the code and that there is an inherent memory leak, I tested the application by opening the html page in the following browsers: Firefox 20.0.1, Safari 5.1.7 and Chrome 26.0.1410.64 m. Regardless of the test that is chosen, local or global array, I do not see the same behaviour. After a certain amount of time the memory is reclaimed and the test continues until I terminate it by closing the browser.

      I apologize for the length of the description but I wanted to provide as much relevant information as possible. I will post the test application in the next comment.




            peterz Peter Zhelezniakov
            duke J. Duke (Inactive)
            0 Vote for this issue
            6 Start watching this issue