esp32-snippets: Does "BLEScan::start()" has issue of memory leak?

Hi.

We’d like to use “BLEScan::start()” for receive “Advertising Data” including sensor value permanently. We’ve tried use it by below program, but ESP32 had restarted by lack HeapSize.

void setup() {
 Serial.begin(115200);
 BLEDevice::init("");
 pBLEScan = BLEDevice::getScan(); //create new scan
 pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
 pBLEScan->setActiveScan(true);
}

void loop() {
 Serial.print("Free HeapSize: ");
 Serial.println(esp_get_free_heap_size());
 pBLEScan->start(3);
 delay(1000);
}

Shouldn’t “BLEScan::start()” called from “loop()” function? Or does “BLEScan::start()” has issue of memory leak?

Please could you confirm this question?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 25

Most upvoted comments

@kymybk Ok, i found that memory leak in BLEScan. I am working now on multi connect implementation and i have to change a little bit BLEScan class so it will be fixed in it. Thanks again for reporting and help with tests.

If you want to fix it just for now then it is here: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/BLEScan.cpp#L201

Object is deleted from vector but is not destroyed.

Before it will be merged to library you can get it from this gist: https://gist.github.com/chegewara/6fc38e4127a7e18bb5b0bb4367aa33d1

I (461164) SampleClient: Advertised Device: Name: ESP32, Address: 30:ae:a4:3f:24:4e, txPower: 3
I (461165) SampleClient: free heap ammount: 111400
I (461170) SampleClient: Advertised Device: Name: ESP32, Address: 30:ae:a4:43:a1:72, txPower: 3
I (461178) SampleClient: free heap ammount: 111300
W (464130) SampleClient: current size of scanned devices (and most likely connected) 2
I (464130) SampleClient: start scan
I (464571) SampleClient: Advertised Device: Name: ESP32, Address: 30:ae:a4:43:a1:72, txPower: 3
I (464572) SampleClient: free heap ammount: 111400
I (464659) SampleClient: Advertised Device: Name: ESP32, Address: 30:ae:a4:3f:24:4e, txPower: 3
I (464660) SampleClient: free heap ammount: 111192
W (467137) SampleClient: current size of scanned devices (and most likely connected) 2
I (467137) SampleClient: start scan
I (467177) SampleClient: Advertised Device: Name: ESP32, Address: 30:ae:a4:43:a1:72, txPower: 3
I (467178) SampleClient: free heap ammount: 111400
I (467183) SampleClient: Advertised Device: Name: ESP32, Address: 30:ae:a4:3f:24:4e, txPower: 3
I (467191) SampleClient: free heap ammount: 111300

I know its quite old issue, sorry for delay, but i am working on few updates and i have this on todo list. https://github.com/chegewara/esp32-snippets/issues/7