B4J Question How to avoid repeated chart initialization?

positrom2

Active Member
Licensed User
Longtime User
I am plotting repeatedly data coming in via asyncsteamstext by calling "Sub createlinechart" when the complete data set has been received.
B4X:
Sub createlineChart
If LCGetDataJO.IsInitialized Then LCGetDataJO.RunMethod("remove",Array As Object(SeriesJO))
SeriesJO.InitializeNewInstance("javafx.scene.chart.XYChart.Series",Null)
GetDataJO = SeriesJO.RunMethod("getData",Null)
For i=0 To 132
AddData(GetDataJO, i, test1(i))
Next
series2.InitializeNewInstance("javafx.scene.chart.XYChart.Series",Null)
GetDataJO=series2.RunMethod("getData",Null)
AddData(GetDataJO,Idxmin+4,ma)
AddData(GetDataJO,Idxmin+4,mi)
series1.InitializeNewInstance("javafx.scene.chart.XYChart.Series",Null)
GetDataJO=series1.RunMethod("getData",Null)
AddData(GetDataJO,Idxmax+4,ma)
AddData(GetDataJO,Idxmax+4,mi)
LCGetDataJO = LineChartJO.RunMethod("getData",Null)
'LCGetDataJO.RunMethod("add",Array As Object(SeriesJO))
LCGetDataJO.RunMethod("addAll",Array As Object(Array As Object(SeriesJO,series1,series2)))
End Sub
The Chart is plotted fine, but in each call of "createlinechart" the Java memory occupation is increased until the app runs very slow and finally stalls.
Maybe the cause could be the "InitializeNewInstance" that is called upon each call of this sub. I tried to move those initializations to the AppStart sub, but that results in an Java exception.
Is there a way to fix this?
 

stevel05

Expert
Licensed User
Longtime User
I can't see why you can't move them to AppStart, without a running app to try it on. But you could try moving them to the beginning of the sub and do an:

B4X:
If Not(series2.IsInitialized) then
  series2.InitializeNewInstance .....

you may then have to clear the existing data as well.
 
Upvote 0

positrom2

Active Member
Licensed User
Longtime User
I tried this for any series.-no change
B4X:
If SeriesJO.IsInitialized=False then InitializeNewInstance("javafx.scene.chart.XYChart.Series",Null)
you may then have to clear the existing data as well.
I tried this
B4X:
If LCGetDataJO.IsInitialized=true Then LCGetDataJO.RunMethod("remove",Array As Object(SeriesJO)
for any series. No change.
Is that what you mean by clearing?
I suspect a memory leak (see my post under "Bugs?").
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Yes, that is what I meant, but you'd have to do it for series1 and series2 as well as seriesJO.
 
Upvote 0

positrom2

Active Member
Licensed User
Longtime User
you'd have to do it for series1 and series2 as well as seriesJO.
Yes, I had tried that also. No change. Task manager shows steadily increasing memory occupation of java.exe.
It really seems to be memory leak problem. You can see that in the task manager even when you run Erel's Smiley example.
http://www.basic4ppc.com/android/forum/attachments/smiley-zip.20538/
Really bad. If that can't be fixed Javafx is merely kind of toy.
 
Upvote 0
Top