Skip to content
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

[Feature Request] Ability to clean up memory #12

Closed
schlaegerz opened this issue Apr 14, 2020 · 1 comment
Closed

[Feature Request] Ability to clean up memory #12

schlaegerz opened this issue Apr 14, 2020 · 1 comment

Comments

@schlaegerz
Copy link

In my situation I am only using ble to do setup, so after my device is set up I would like to be able to completely clean up the memory and move on. So it would be great if there was a method to clean up the singletons, or some way for me to delete.

I have found I can do most with client code, but the singleton objects are impossible to fix up without library changes.

Here is what I was thinking


void NimBLEDevice::cleanup() {
  if(NimBLEDevice::m_pServer == nullptr) {
      delete NimBLEDevice::m_pServer;
      NimBLEDevice::m_pServer = nullptr;
   }
  if(NimBLEDevice::m_bleAdvertising== nullptr) {
      delete NimBLEDevice::m_bleAdvertising;
      NimBLEDevice::m_bleAdvertising= nullptr;
   }
  if(NimBLEDevice::m_pScan== nullptr) {
      delete NimBLEDevice::m_pScan;
      NimBLEDevice::m_pScan= nullptr;
   }
   for(auto it = m_cList.cbegin(); it != m_cList.cend(); ++it)
   {
      deleteClient(*it);
   }
   // Whatever other clean up needs to be done.
  
}
@h2zero
Copy link
Owner

h2zero commented Apr 14, 2020

That's a good idea, perhaps that code should just be added to NimBLEDevice::deinit() then you could make one call to completely stop all BLE functions. You can reinit after that if you need to as well.

h2zero added a commit that referenced this issue Jul 21, 2020
Adds the ability to clear all resources consumed during BLE operation when deinitializing and shutting down BLE.
Useful when BLE is used intermittently or in a task that initializes, performs operations then deinitializes.

By setting the clearAll parameter to true all created BLE objects will be deleted, freeing the memory for other tasks.

Warning: This will invalidate any pointers that may be referencing the deleted objects.
@h2zero h2zero closed this as completed in 05c68ed Jul 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants