Memory leak of JavaScript chart(by HTMLViewer)

I’m using a JavaScript Chart through HTMLViewer(WebKit), it looks fine but there is a critical issue.
Since my application started, the memory consumption is increased gradually. For 7 hours, it reaches 1GB of system memory.(Windows)
Without this Chart feature, no more memory leak issue.

I tried to narrow down the issue by commenting the ExecuteJavaScript method.
If I don’t call the JavaScript, I don’t see the memory leak issue.

I think I call the below statement periodically, I believe I could get a workaround, but I want to find the root cause of this issue.
ReaderHTMLChart.ExecuteJavascript(“location.reload()”)

Can anyone have the similar issue before? Or let me know how to debug?
This one is very critical to me. Please help me out.

  If RepSRCWorking Then  
 
  'Get 200 rows ( 1 minute interval )
      
    Else
      
      Dim root as new JSONItem
      Dim finalString As String
      
      While Not rs.EOF
        
        Dim Person as new JSONItem
         
        Person.Value("date") =     rs.Field("GATHER_TIME").StringValue
        Person.Value("Latency") =     rs.Field("LATENCY").StringValue
        Person.Value("Backlog") =     rs.Field("BACKLOG").StringValue

        root.append Person
        rs.MoveNext
        
      Wend
      
      
      ReaderHTMLChart.ExecuteJavaScript("showChart(" + root.toString + ");")
      ReaderHTMLChart.ExecuteJavaScript("updateChart(" + root.toString + ");")  
      
    End If
    
  Else
    Return
    
  End If
  
  Exception err as RunTimeException
    MsgBox err.message

Try running your JavaScript code in a web browser and see if it does the same thing…

Yes, I already tried to run it on web browser, but I don’t see the memory leak issue.

The below command doesn’t seem to refresh HTML(JavaScript).
ExecuteJavascript(“location.reload()”) or ExecuteJavascript(“location.reload(True)”)

Every 1 minute, I update the Chart and at the same time I tried to call the method above, it helps a little bit but still consumes the memory gradually.

Is there any way to refresh HTML(JavaScript) completely like I close the application and restart it?

ReaderHTMLChart.ExecuteJavaScript("showChart(" + root.toString + ");")
ReaderHTMLChart.ExecuteJavaScript("updateChart(" + root.toString + ");")

your string don’t need quotes?

ReaderHTMLChart.ExecuteJavaScript("showChart(" + "'" + root.toString + "'" + ");")
ReaderHTMLChart.ExecuteJavaScript("updateChart(" + "'" + root.toString + "'" + ");")

I’m not sure just a guess.

[quote=199749:@changwon lee]The below command doesn’t seem to refresh HTML(JavaScript).
ExecuteJavascript(“location.reload()”) or ExecuteJavascript(“location.reload(True)”)

Every 1 minute, I update the Chart and at the same time I tried to call the method above, it helps a little bit but still consumes the memory gradually.
[/quote]

You want to put true in lowercase, otherwise it does nothing :

HTMLViewer1.ExecuteJavaScript("location.reload(true) ;")

Difficult to know what the memory leak issue is. Chances are it comes from the chart JavaScript somewhere.

Just a wild guess since I have no way to reproduce the problem, you could try to close the HTMLViewer and create a new one.

If you make the HTMLViewer1 a control set, you can use that :

HTMLViewer1(0).close DIM H as new HTMLViewer1

It should completely reset the memory of the HTMLViewer. Short of closing the app itself, that is the best I can think of.

This issue can be easily reproduced, and I made a simple one to show you.
link text

I think closing the HTMLViewer doesn’t help to clear the whole memory from my test, and only terminating the Application did clear the memory.

If you’re available please check the attached file.

A very quick check shows approximately a 1 MB increase at every data update from the 12 MB or so at start . Closing the HTMLViewer or the window does decrease a bit, but then, the next data update comes back to that value.

Since the only way to clear memory is a restart, here is what I placed in a Restart button :

Sub Action() dim f as FolderItem = app.ExecutableFile f.Launch quit End Sub

The new instance of the app starts at 12MB.

You could periodically do that to clear memory. From what I see, the restart does blink, but it is probably fast enough to not be too much of an issue.

Thank you for the comment.

Tried to restart it. Yes as you said, I see the app again instantly.
However, restarting up the whole application wouldn’t be good experience to users. Normally there would be several database connections and server connections, so those ones are also disconnected.

Best Regards,

[quote=200013:@changwon lee]Thank you for the comment.

Tried to restart it. Yes as you said, I see the app again instantly.
However, restarting up the whole application wouldn’t be good experience to users. Normally there would be several database connections and server connections, so those ones are also disconnected.
,[/quote]

I wonder if it would not be possible to uncouple the app itself and the presentation of data. You could have a main app that manages the databases and connections, and a helper that sole purpose is to present the data through the HTMLViewer. Both apps would communicate through an IPCSocket. That would allow restarting the presentation module without touching the main app. In practice to the user that would simply appear as just another window.

I was thinking of making a DashBoard having serveral Chars. In that area, I believe that your approach would be great.
But, in my main Application, I need to keep 2 Chars for the some information.

link text

With below code, I think it doesn’t consume a lot of memory. Actually I modified the JS as well.
HTMLChart.ExecuteJavaScript(“location.reload(true) ;”)
HTMLChart.ExecuteJavaScript(“updateData();”)

However, ‘reload’ job doesn’t seem to proceed quickly so the Chart disappear instantly.

What can be done for confirming that ‘reload’ job is completed?

Actually, your main app could be a windowless app, and all display could be done by the helper. Think of the helper as an other form of window.

The HTMLViewer has events for that. DocumentComplete fires in sequences when a page is complete. I believe it should fire with reload.

Otherwise you got the onload event in JavaScript : onload Event

I have modified the JS script and tested it again. I saw the big difference.
I made a mistake to call the JS function.

With the previous wrong version: I call ‘showChart’ function and it tried to make a new Chart every time I call the ‘showChart’ function. Eventually, it made a different chart instance and retained with the memory.

function showChart() {
var chart = AmCharts.makeChart(“chartdiv”, {

From the advice of Amcharts support, I have modified it like below and just call ‘updateChart’ function instead.

var chart = AmCharts.makeChart(“chartdiv”, {

function updateChart(chartData) {
chart.dataProvider = chartData;
chart.validateData();
};

With the previous one, it consumed about 1GB of system memory, now just 100MB for the same period.

To reduce the memory consumption more, I will try to use ‘reload’ function by using DocumentComplete event of HTMLViewer.
HTMLChart.ExecuteJavaScript(“location.reload(true) ;”)

Thanks for your great help!