Skip to content

memory leak on blutooth connection disconnect #5500

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

Closed
elkstoritve opened this issue Oct 23, 2021 · 1 comment
Closed

memory leak on blutooth connection disconnect #5500

elkstoritve opened this issue Oct 23, 2021 · 1 comment
Milestone

Comments

@elkstoritve
Copy link

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

@tannewt tannewt added the nordic label Oct 25, 2021
@tannewt tannewt added this to the 7.x.x milestone Oct 25, 2021
@dhalbert
Copy link
Collaborator

This is believe is the same as adafruit/Adafruit_CircuitPython_BLE#146, which was recently fixed by adafruit/Adafruit_CircuitPython_BLE#147. Please reopen if you think it is a core problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants