question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

scanBleDevices causes memory leak

See original GitHub issue

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

  • Canary showing a memory leak

Expected result

  • Canary not showing a memory leak

Minimum code snippet reproducing the issue

scanDisposable = RxBle.get()
    .scanBleDevices(
        ScanSettings.Builder()
            .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
            .setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES)
            .build()
    )
    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .doOnError {
        onScanError() // commenting this out stops leak
    }
    .doOnNext {
    }
    .subscribe()

Logs from the application running with settings:

https://github.com/seljabali/rxandroidble2-leak/blob/master/leakLog.txt

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:18 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
dariuszseweryncommented, Sep 25, 2019

This looks exactly as before, starting the leak at Android’s BleScanCallbackWrapper. I will try to run it once I will get my hands on an API 29 device.

1reaction
seotradercommented, Aug 1, 2020

Hello, I’ve created a PR with a solution to the issue

https://github.com/Polidea/RxAndroidBle/pull/708

Hope it can be merged soon

Read more comments on GitHub >

github_iconTop Results From Across the Web

Memory Leak scanning BLE devices - arduino - Stack Overflow
I'm using an ESP32 to scan BLE advertisers but I have a memory leak. If I comment out line 94 (pBLEScan->start) the leak...
Read more >
Everything you need to know about Memory Leaks in Android.
How we can cause a leak? A memory leak can easily occur in Android when AsyncTasks, Handlers, Singletons, Threads, and other components are...
Read more >
Fix your Android Memory Leaks in Fragments - Procore
Accessing the binding object before onViewCreated is called will cause the app to crash because the DataBinding object inside that delegate hasn't been...
Read more >
Preventing and detecting memory leaks in Android apps
Memory leaks can cause your Android app to crash, causing frustration and lower usage. Learn how to fix them in this guide.
Read more >
ANR_milanac007的博客-CSDN博客
private IBLEDevice scanBLEDevice(final String sn) throws AKeyException { ... 关键词:Memoryleak/Thread leak ... This will most likely cause the bui.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found