I have discovered an endlessly increasing memory usage in my app.
After tracking with VisualVM I noticed that only the resumable subs occupy more and more memory with time. (The shown Allocated Bytes is the delta in 3 Hours!)
The biggest memory consumption comes from this Timer Sub wich increase the Memory around 70 bytes per tick. The Timer ticks the sub every 5 Seconds, but the code will only compute after some time (around every 10 minutes):
But as you can see, this is not the only resumable Sub wich eats memory.
Also this simple sub:
Is there anything special about Resumable Subs wich i need to know to prevent a Memory Leak?
After tracking with VisualVM I noticed that only the resumable subs occupy more and more memory with time. (The shown Allocated Bytes is the delta in 3 Hours!)
The biggest memory consumption comes from this Timer Sub wich increase the Memory around 70 bytes per tick. The Timer ticks the sub every 5 Seconds, but the code will only compute after some time (around every 10 minutes):
B4X:
Sub updateplugins_tick
For Each App As String In forceUpdates.Keys
If forceUpdateTime.Get(App) + (forceUpdates.Get(App)*1000) < DateTime.Now Then
Log("force update "&App)
forceUpdateTime.Put(App,DateTime.Now)
Dim Result As Map =plugin.RunPlugin(App, "start", CreateMap("AppDuration":appDuration))
If Result.Get("needDownload")>0 Then
For i=1 To Result.Get("needDownload")
Dim params As Map
params.Initialize
params.Put("Handler", Me)
params.Put("jobNr", i)
wait for (plugin.RunPlugin(App, "download", params)) JobDone(j As HttpJob)
params.Put("response", j)
plugin.RunPlugin(App, "httpResponse", params)
j.Release
Next
End If
End If
Sleep(100)
Next
If (lastUpdateAll + (DB.get("updateInterval")*1000)) < DateTime.Now Then
lastUpdateAll=DateTime.Now
If Not(isupdating) Then updateAll
End If
End Sub
But as you can see, this is not the only resumable Sub wich eats memory.
Also this simple sub:
B4X:
Sub switch
Dim i As Int = Rnd(1,5)
Select i
Case 1
For y=0 To 8
drawLine(0,y,31,y,wheel(y*32))
drawLine(0,y-1,31,y-1,Array As Int(0,0,0))
show
Sleep(40)
Next
Case 2
For y=8 To -1 Step -1
drawLine(0,y,31,y,wheel(y*32))
drawLine(0,y+1,31,y+1,Array As Int(0,0,0))
show
Sleep(40)
Next
Case 3
For x=0 To 32
drawLine(x,0,x,7,wheel(x*7))
drawLine(x-1,0,x-1,7,Array As Int(0,0,0))
show
Sleep(20)
Next
Case 4
For x=32 To -1 Step-1
drawLine(x,0,x,7,wheel(x*7))
drawLine(x+1,0,x+1,7,Array As Int(0,0,0))
show
Sleep(20)
Next
End Select
CallSubDelayed(Main,"switchFinish")
End Sub
Is there anything special about Resumable Subs wich i need to know to prevent a Memory Leak?
Last edited: