Skip to content

memory leak on blutooth connection disconnect #5500

Closed
@elkstoritve

Description

@elkstoritve

CircuitPython version

Adafruit 6.3 and 7 tested on nrf itsybitsy

Adafruit CircuitPython 6.3.0 on 2021-06-01; Adafruit ItsyBitsy nRF52840 Express with nRF52840

Code/REPL

import gc
import time
from adafruit_ble import BLERadio

ble = BLERadio()
devices = set()


while True:
    while ble.connected:
        connection=ble.connections[0]
        time.sleep(2)
        connection.disconnect()
        print([gc.mem_free(),devices])
        time.sleep(5)
        gc.collect()


    print("device disconnected, scanning for new devices")
    print([gc.mem_free(),devices])


    for advertisement in ble.start_scan(timeout=10, minimum_rssi=-90):
        shortname=advertisement.short_name
        macaddress=advertisement.address
        devices.add(macaddress)
        addr = advertisement.address
        rssi = advertisement.rssi
        print(["connecting",addr,rssi,gc.mem_free(),devices])
        try:
            ble.connect(advertisement,timeout=5)
        except:
            print("can not connect")
        time.sleep(2)
        break
    ble.stop_scan()
    gc.collect()

Behavior

Traceback (most recent call last):
File "code.py", line 80, in
File "adafruit_ble/init.py", line 250, in start_scan
MemoryError: memory allocation failed, allocating 42241 bytes

Description

When doing BLE connect and disconnect, "connection.disconnect()" does not release memory after 1 hour
memory is exhausted, and finished with error.

Check bellow free memory is droping 3792,2400,2032... etc until error.

[5152, {

}]
device disconnected, scanning for new AERAs
[5728, {}]
['connected', , -53, 3792, {}]
[1, 1]
[4272, {}]
device disconnected, scanning for new AERAs
[4848, {}]
['connected', , -56, 2400, {}]
[1, 0]
[3392, {}]
device disconnected, scanning for new AERAs
[3968, {}]
supervisor reload
['connected', , -62, 2032, {}]
[1, 1]

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions