-
Notifications
You must be signed in to change notification settings - Fork 588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
scanBleDevices causes memory leak #607
Comments
What device/OS have you tested on? |
Samsung Galaxy S8 |
What OS version? |
Oreo: 8.0, Api: 26 |
Correct me if I am wrong but it seems that the root-cause of the leak is
Which is a part of Android OS — not library's? |
I have looked through the classes that are referenced by the trace but all of those should be garbage collected normally with their |
I have modified the example so it does not use
LeakCanary result:
I think that this issue should be checked against the newest Android OS version and reported on Google Issue Tracker |
Great investigative efforts @dariuszseweryn! Thank you. I'll create a Google Issue accordingly, and post it back here as a comment -- closing ticket. |
Hey @dariuszseweryn. I've updated the project to target Q/Api29. In testing on an S8 using Android 9, I found that the ScanCallBack doesn't leak however the Rx implementation does leak. For convenience, I've created side by side fragments between the two implementations on the github project to easily switch between the two in its MainActivity. |
Hello @seljabali — I do not have an Android phone with me to test this out, could you attach leak traces? |
here you go @dariuszseweryn:
|
This looks exactly as before, starting the leak at Android's |
Update — I have tested on Android 10, API 29 Google Pixel device and the problem seems to be fixed without any changes to the library. Closing. Thank you for the report.
|
Hello ! Sorry I think that this leak is not fixed. I got the same problem in my code. I did some investigations with my own code linked to this leak. I got the following leak trace : https://gist.github.com/LeMimit/f532873e8c891ed4d89d874276c9441f I cloned the code at https://github.com/seljabali/rxandroidble2-leak. With May be this is linked to the fact that in the library in final SCAN_CALLBACK_TYPE scanCallback = createScanCallback(emitter); The emitter is used in the callback which keep a reference. The same emitter is subscribed in the fragment which keep a reference to the Fragment itself. When the fragment is destroyed we have a leak. Thanks ! |
Pinging @dariuszseweryn, can case he didn't notified. |
There is one more thing to this issue that may be important as it may cause race conditions. Scan cancellation is asynchronous (all BLE actions are to be precise). So when the user disposes the stream actual scan stop happens on a different thread. Leak Canary can create a snapshot before the scan stop happens. This would also explain why I did not notice any leaks when I have tested on Android 10. Check could be as simple as:
|
Hello everyone, Is there any updates about this leak? I do have the same leak happening on Android 9 using RX Thanks |
Hello, Hope it can be merged soon |
Summary
Doing a basic scan of ble devices causes a memory leak despite ending the scan subscription at
onStop()
.Library version
1.10.1
Preconditions
Have sample app cloned & loaded: https://github.com/seljabali/rxandroidble2-leak
Steps to reproduce actual result
1. Enable Bluetooth on device
2. Enable GPS
3. Open app
4. Hit back button
5. Pull system drop down
6. Wait for Canary to analyze heap
7. Canary momentarily shows leak.
Actual result
Expected result
Minimum code snippet reproducing the issue
Logs from the application running with settings:
https://github.com/seljabali/rxandroidble2-leak/blob/master/leakLog.txt
The text was updated successfully, but these errors were encountered: