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
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?
[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 :
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.
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=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.
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?
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) ;”)