-
Notifications
You must be signed in to change notification settings - Fork 199
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
Leaking BleAdapter #563
Comments
@JamesMcIntosh did you test if this happens with the memory profiler? |
Hi @michael-ottink, I don't think that I checked it with a profiler, I came to this suggestion from a visual inspection of the code and the reported behaviour around hot restarts. |
I profiled it and it is leaking as expected. |
To get around the hot restart issue the createClient method can either destroy and recreate or reuse the existing one. After testing out the destroyClient method and it looks like the destroy it still leaks. The leak originates in MultiPlatformBleAdapter is because of RxJava1's subscriptions to Observers holds strong references to the anonymous inner classes inside BleModule i.e onError and onNext. More information: https://medium.com/@scanarch/how-to-leak-memory-with-subscriptions-in-rxjava-ae0ef01ad361 |
If you create multiple clients when
FlutterBleLibPlugin.createClient()
overwrites the existingBleAdapter
.This means you can never destroy the previous clients, I'm pretty sure that this could cause a memory leaks as there are listeners attached etc.
If you guard against creating a second one then
bleAdapter.createClient()
will need to be skipped also as it will cause the same issue with leaks asBleModule
is written assuming the same pattern which will overwrite the client, see BleModule.java#L110The text was updated successfully, but these errors were encountered: