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

Leaking BleAdapter #563

Open
JamesMcIntosh opened this issue Dec 16, 2020 · 4 comments
Open

Leaking BleAdapter #563

JamesMcIntosh opened this issue Dec 16, 2020 · 4 comments

Comments

@JamesMcIntosh
Copy link
Contributor

JamesMcIntosh commented Dec 16, 2020

If you create multiple clients when FlutterBleLibPlugin.createClient() overwrites the existing BleAdapter.

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 as BleModule is written assuming the same pattern which will overwrite the client, see BleModule.java#L110

@duck-dev-go
Copy link

@JamesMcIntosh did you test if this happens with the memory profiler?

@JamesMcIntosh
Copy link
Contributor Author

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.

@JamesMcIntosh
Copy link
Contributor Author

I profiled it and it is leaking as expected.

@JamesMcIntosh
Copy link
Contributor Author

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

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