Post by kryssi on Feb 23, 2024 10:15:06 GMT
Hi dear developers,
I'm having an issue with rhomobile application using GeoLocation module, as soon as I call GeoLocation.set_notification my application will start leaking memory eventually crashes when no more memory is available.
I've verified in the adb logs that the crash reason is outofmemory problem. I've started to monitor the app memory usage and I can see the leak live, it happens quite fast, when calling GeoLocation.set_notification with the default 0 parameter on my zebra device means getting callback around 3-4 times a second. Those callbacks seem to leak memory.
The ruby view itself is very simple with no complex logic, here is the code I use:
The memory leak happens even when if the !last_stop.empty? condition is never met, so that's not the case.
In the beginning the memory usage of the app looks like this: (adb shell dumpsys meminfo is.edico.delivery -D):
At 9:20:
At 9:33
It seems like "Private other" memory is leaking, most likely ruby or c code.
At 9:50:
It will take around 1-2 hours for the application to crash. Last time I checked my app was using 400MB memory in total few minutes before it crashed.
I've simplified my view and commented out most of the logic and the memory leak is still there.
Do you have any ideas how to fix this?
Best regards,
Krystian
I'm having an issue with rhomobile application using GeoLocation module, as soon as I call GeoLocation.set_notification my application will start leaking memory eventually crashes when no more memory is available.
I've verified in the adb logs that the crash reason is outofmemory problem. I've started to monitor the app memory usage and I can see the leak live, it happens quite fast, when calling GeoLocation.set_notification with the default 0 parameter on my zebra device means getting callback around 3-4 times a second. Those callbacks seem to leak memory.
The ruby view itself is very simple with no complex logic, here is the code I use:
def geo_callback
@params.delete('rho_callback')
status = @params.delete('status')
if status != "ok"
return
end
satellites = @params.delete('satellites')
altitude = @params.delete('altitude')
known_position = @params.delete('known_position')
available = @params.delete('available')
accuracy = @params.delete('accuracy')
last_stop = Rho::RhoConfig.last_stop
curr_stop = Rho::RhoConfig.current_tripstop
if !last_stop.empty?
#calculate the distance
lat = @params['latitude'].to_f
lon = @params['longitude'].to_f
speed = @params['speed'].to_f
@params['ls'] = last_stop
@params['cs'] = curr_stop
last_lat, last_lon, last_ts = last_stop.split(',')
dist = ApplicationHelper.distance(last_lat.to_f, last_lon.to_f, lat, lon)
@params['distance'] = dist
#if distance from last stop is more than 50m or speed reaches ~ 18 km/h (5 m/s)
min_distance = 50/1000.0 #km
min_speed = 5 #m/s
if (dist > min_distance || speed > min_speed) && !curr_stop.empty?
Rho::RhoConfig.last_stop = ''
js = "EdicoHH.startTripStop(#{curr_stop})"
Rho::Log.warning("Starting tripstop journey to #{curr_stop}, last_ts: #{last_ts}, dist: #{dist} speed: #{speed}", "EdicoHH")
WebView.executeJavascript(js)
end
end
end
The memory leak happens even when if the !last_stop.empty? condition is never met, so that's not the case.
In the beginning the memory usage of the app looks like this: (adb shell dumpsys meminfo is.edico.delivery -D):
At 9:20:
Applications Memory Usage (in Kilobytes):
Uptime: 112386601 Realtime: 250744933
** MEMINFO in pid 15834 [is.edico.delivery] **
Pss Private Private SwapPss Heap Heap Heap
Total Dirty Clean Dirty Size Alloc Free
------ ------ ------ ------ ------ ------ ------
Native Heap 23206 23172 0 1 33892 29533 4358
Dalvik Heap 7596 7568 0 0 15165 2877 12288
Dalvik Other 2228 2224 0 0
Stack 60 60 0 0
Ashmem 338 220 0 0
Gfx dev 6636 6636 0 0
Other dev 32 0 32 0
.so mmap 9884 472 7896 2
.jar mmap 4486 0 2996 0
.apk mmap 17402 444 8752 0
.ttf mmap 53 0 16 0
.dex mmap 2728 612 2116 0
.oat mmap 86 0 36 0
.art mmap 5971 5776 84 7
Other mmap 1078 296 388 0
Unknown 8025 8012 4 0
TOTAL 89819 55492 22320 10 49057 32410 16646
App Summary
Pss(KB)
------
Java Heap: 13428
Native Heap: 23172
Code: 23340
Stack: 60
Graphics: 6636
Private Other: 11176
System: 12007
TOTAL: 89819 TOTAL SWAP PSS: 10
Objects
Views: 16 ViewRootImpl: 1
AppContexts: 6 Activities: 1
Assets: 20 AssetManagers: 0
Local Binders: 98 Proxy Binders: 47
Parcel memory: 15 Parcel count: 56
Death Recipients: 5 OpenSSL Sockets: 0
WebViews: 1
SQL
MEMORY_USED: 0
PAGECACHE_OVERFLOW: 0 MALLOC_SIZE: 0
At 9:33
Applications Memory Usage (in Kilobytes):
Uptime: 113204601 Realtime: 251562934
** MEMINFO in pid 15834 [is.edico.delivery] **
Pss Private Private SwapPss Heap Heap Heap
Total Dirty Clean Dirty Size Alloc Free
------ ------ ------ ------ ------ ------ ------
Native Heap 22351 22316 0 1 32936 28741 4195
Dalvik Heap 9593 9560 0 0 15119 2831 12288
Dalvik Other 2073 2072 0 0
Stack 60 60 0 0
Ashmem 328 204 0 0
Gfx dev 6644 6644 0 0
Other dev 32 0 32 0
.so mmap 10051 472 7924 2
.jar mmap 4556 0 2932 0
.apk mmap 17834 444 9076 0
.ttf mmap 53 0 16 0
.dex mmap 2756 612 2144 0
.oat mmap 82 0 32 0
.art mmap 6402 5780 452 4
Other mmap 1268 192 548 0
Unknown 56908 56896 4 0
TOTAL 140998 105252 23160 7 48055 31572 16483
App Summary
Pss(KB)
------
Java Heap: 15792
Native Heap: 22316
Code: 23652
Stack: 60
Graphics: 6644
Private Other: 59948
System: 12586
TOTAL: 140998 TOTAL SWAP PSS: 7
Objects
Views: 16 ViewRootImpl: 1
AppContexts: 6 Activities: 1
Assets: 20 AssetManagers: 0
Local Binders: 65 Proxy Binders: 38
Parcel memory: 28 Parcel count: 162
Death Recipients: 4 OpenSSL Sockets: 0
WebViews: 1
SQL
MEMORY_USED: 0
PAGECACHE_OVERFLOW: 0 MALLOC_SIZE: 0
It seems like "Private other" memory is leaking, most likely ruby or c code.
At 9:50:
Applications Memory Usage (in Kilobytes):
Uptime: 114196016 Realtime: 252554349
** MEMINFO in pid 15834 [is.edico.delivery] **
Pss Private Private SwapPss Heap Heap Heap
Total Dirty Clean Dirty Size Alloc Free
------ ------ ------ ------ ------ ------ ------
Native Heap 22374 22340 0 1 32956 28975 3980
Dalvik Heap 5130 5100 0 0 15033 2745 12288
Dalvik Other 2049 2048 0 0
Stack 60 60 0 0
Ashmem 328 204 0 0
Gfx dev 6644 6644 0 0
Other dev 32 0 32 0
.so mmap 10071 472 7944 2
.jar mmap 4453 0 2900 0
.apk mmap 17821 444 9064 0
.ttf mmap 53 0 16 0
.dex mmap 2756 612 2144 0
.oat mmap 79 0 32 0
.art mmap 6393 5780 444 4
Other mmap 1308 220 548 0
Unknown 119684 119672 4 0
TOTAL 199242 163596 23128 7 47989 31720 16268
App Summary
Pss(KB)
------
Java Heap: 11324
Native Heap: 22340
Code: 23628
Stack: 60
Graphics: 6644
Private Other: 122728
System: 12518
TOTAL: 199242 TOTAL SWAP PSS: 7
Objects
Views: 16 ViewRootImpl: 1
AppContexts: 6 Activities: 1
Assets: 20 AssetManagers: 0
Local Binders: 65 Proxy Binders: 38
Parcel memory: 18 Parcel count: 92
Death Recipients: 4 OpenSSL Sockets: 0
WebViews: 1
SQL
MEMORY_USED: 0
PAGECACHE_OVERFLOW: 0 MALLOC_SIZE: 0
It will take around 1-2 hours for the application to crash. Last time I checked my app was using 400MB memory in total few minutes before it crashed.
I've simplified my view and commented out most of the logic and the memory leak is still there.
Do you have any ideas how to fix this?
Best regards,
Krystian