Bug? Memory leak?

positrom2

Active Member
Licensed User
Longtime User
In the B4J "Questions" section I have asked for a solution to avoid slowing down and finally stalling the application when plotting live data repeatedly (How to avoid repeated chart initialization?)
Further searching revealed rumors about a memory leak in Javafx. If that were true it would be really bad. I can't even finish one instrument run before it stops working.
Even the Smiley example
http://www.basic4ppc.com/android/forum/attachments/smiley-zip.20538/
shows memory occupation growing up steadily.
 
Last edited:

agraham

Expert
Licensed User
Longtime User
There is a tool called VisualVm that ships with the JDK. It is jvisualvm.exe in your Java/jdk1.7.xxx/bin folder in Program Files. It can show you memory use, Profiler tab -> Memory. There is a plugin called VisualGC in Tools-> Plugins -> Available Plugins that shows more information about the Garbage Collector. Install theVisualVM-Extensions as well.

In JDK 7u40 and later there is also Java Mission Control - jmc.exe. Right click on your app in the JVM Browser tab and select Start JMX Console or equivalently expand it and double click MBean Server. There is a demo here
 

positrom2

Active Member
Licensed User
Longtime User
The memory window in VisualVM with my code shows a sawtooth with quickly increasing baseline. Clicking on Garbage collection does not affect my problem (stalling my app).
I looked at Erel's smiley example. Also with this, the windows task manager shows that java.exe *32 fills memory by about 900 K in 5 minutes. Interestingly, the memory occupation of visualvm.exe *32 itself is increasing at a similar rate. So, that seems to be a general problem.
I am not sure what jmc.exe could help (your post seems to be incomplete).
 

agraham

Expert
Licensed User
Longtime User
Smiley looks fine to me in both VisualVM and JMC. I see no signs of a memory leak. There are two sawtooth patterns in Smiley, one with a frequency of about 10 seconds on a slightly rising baseline, then a reset of that baseline after about 10 minutes. I'm watching it in JMC. In what way is my post incomplete?
 

positrom2

Active Member
Licensed User
Longtime User
There is a demo here
no dot rather quarter of white space.
Using windows task manager, java.exe occupied memeory does not increse with Smiley? With that it's very small amount, wait for two minutes.
By the way, how to increase VM memory? I used java control panel, but changing settings there did do nothing.
 

agraham

Expert
Licensed User
Longtime User
no dot rather quarter of white space.
Looks fine here in both Chrome and IE11.

You can't make judgements on slow memory leaks over a few minutes and you can't expect the Garbage Collector to fully reclaim all the memory it can each time it runs as it is optimised for efficiency in many ways. I've had JMC and VisualVM watching Smiley for over an hour now and it uses about 40% of the heap. Yes the usage seems to increase over time but if you prod it to perform a GC it falls back to 40% of heap use. It's just the GC being lazy, it will get more aggressive if it needs to.

I don't believe that there is a general problem with memory leaks in JavaFX, it has been around for too long. There may be individual bugs in it that leak but generally no, I don't think so.

For your problem program you should take some "before and after" heap dumps in VisualVM and have it compare them to see what has grown. The heap dumps let you investigate down to the individual object instance and even see the values of its fields.

Google "increase Java heap size"
 

positrom2

Active Member
Licensed User
Longtime User
Yes, debug mode is not helpful in this case. I was reporting on what happens in Release Mode.
Now I don't know what to do. Maybe you can check the structures:
B4X:
Sub astream1_NewText(Text As String)
  Dim s1 As String  
  test1(k)=Text 'Inputdata
  k=k+1
  If k=133 Then
    Idxmax=test1(1)
    Idxmin=test1(2)
    ma=test1(3)
    mi=test1(4)
    For k=0 To 5
      test1(k)=(ma+mi)/2
    Next
    k=0
    s1="x"&Chr(13)&Chr(10)'Request transmission of new Set of Data (133)
    astream1.Write(s1)
    s1=pwm&Chr(13)&Chr(10)  
    astream1.Write(s1)  
    Plott
  End If
End Sub

Sub Plott
  If LCGetDataJ1.IsInitialized=True Then LCGetDataJ1.RunMethod("remove",Array As Object(SeriesJ1))
  SeriesJ1.InitializeNewInstance("javafx.scene.chart.XYChart.Series",Null)
  GetDataJ1 = SeriesJ1.RunMethod("getData",Null)
  For i=0 To 132
    AddData(GetDataJ1, i, test1(i))
  Next
  LCGetDataJ1 = LineChartJ1.RunMethod("getData",Null)
  LCGetDataJ1.RunMethod("add",Array As Object(Array As Object(SeriesJ1)))
End Sub
This runs as a clockwork for about 150 cycles. Then quickly it slows down and will ultimately block the application (I mean finally very very slowly reacting on a Button press to close the app).
Thank you.
 
Last edited:

agraham

Expert
Licensed User
Longtime User
Now I don't know what to do.
I already told you. Run VisualVM. Take a Heap dump (Monitor tab -> HeapDump button) after the first few cycles and a Heap Dump when it slows down and look at the difference (HeapDump Tab -> Classes Sub tab -> Compare with another heap dump ).
 

positrom2

Active Member
Licensed User
Longtime User
Made three Heapdumps, two shortly after starting the app and one when getting very slow. Since I don't know how to print them some
results here: Last-second: lava.lang.objt: Instances +7 , Size: +56, other differences smaller.
Last-first: lava.lang.object: Instances :-21 , Size: -186, int[]: Instances -126, size -625, com.sun.jna.memory Instances -623, size: -14952, java.lang.finalizer: instances: -631, size -20192
P.S.: The logic analyzer shows me that synchronization is not lost between the µC and the PC when close to the "stalling" condition.
Erel: May I mail it to you?
 
Last edited:
Top