Memory leak every disconnection/connection for BLE

I'm investigating some crashes of a data field that connects to a sensor using BLE due to an out of memory condition.

I have been able to replicate the crash when the sensor is disconnected and connected again multiple times. Every time connection is recovered a leak of aprox 0.6 kB happens, so that after some repetitions the data field finally crashes.

There's nothing I can identify in the code that causes this leak, so not sure if it happens at the BLE API layer.

Has anyone observed this behavior?

 I think it could be easy to you to simulate and check this using BLEscan. Could you do a test to know whether this happens or not?

  • I put an extra like in the store version of blescan to display the free memory. That can bounce around as the app is finding new devices, but once stable, the free I see before I connect is the same as I see after I disconnect, so I don't lose any.  I'm using a fr570.

    This may be a bit hard to see with blescan.

  • Thanks, I will do some tests with blescan.

  • The version with free memory (M:) will be available shortly if it's not there already..  Remember, free memory drops each  time a new device is seen

  • I will take this into account and will try to test when seen devices remain the same. 

  • I think you are on to something. I have had a problem with my Tesla key and opening postal boxes, both using BLE. After rebooting the phone or clearing data/cache of the Bluetooth system app clearing cache is not enough), it will work for a few days.

    After uninstalling the Garmin Connect app, it seems the problem is gone.

    It is on a OnePlus 11 pro, with newly installed Oxygen OS 16. Also had the problem with Oxygen OS 15.

    This is my post from Reddit about the Tesla key problem:

    "I've had this problem for over a year, and might have found a solution. The problem was not with the Tesla app, but with the Bluetooth.

    Symptoms: with a few days between, the Bluetooth would not open the car, until I had rebooted the phone. I could still open it through the app. Bluetooth works with other things like headphones etc.
    When rebooting the phone, it would work for a few days.
    One day when i had the problem, I opened the Tesla through the app, and went to get a package, I could not open the postal box either, which also uses Bluetooth. Both the Tesla key and the postal box uses BLE (Bluetooth Low Energy). It seemed that something crashed this service. I found out I could avoid rebooting the phone, and instead clear data and cache for the Bluetooth system app. I created a shortcut for this, but without jailbreaking, it is not possible to make an automation, to clear the data.

    I started troubleshooting through different settings in developer mode, without success.

    POSSIBLE SOLUTION:
    I started looking at other apps that uses Bluetooth, specific the BLE function. I have a Garmin smartwatch for working out, which I had not used for some time. I still had the Garmin Connect app installed. After uninstalling this app, I have not had the problem for 10 days.

    TL;DR: Look for apps using Bluetooth, and try uninstalling them. Start with the BLE apps, as this is the service the Tesla phone key uses"