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

RxBleAdapterStateObservable and DisconnectionRouter is leaked memory #349

Closed
hoanglm4 opened this issue Jan 5, 2018 · 2 comments
Closed
Assignees
Labels
bug Bug that is caused by the library
Milestone

Comments

@hoanglm4
Copy link

hoanglm4 commented Jan 5, 2018

Summary

RxBleAdapterStateObservable and DisconnectionRouter is leaked memory

Library version

1.4.3

Preconditions

Connect to BLE device is failed

Steps to reproduce actual result


1. connect() method is called => waiting until connection is failed

2. connect() method is called again

3. repeat step 1, 2 about 100 times

Please see dumemory capture screen:
DisconnectionRouter
RxBleAdapterStateObservable

Minimum code snippet reproducing the issue

public class CharacteristicOperationExampleActivity extends RxAppCompatActivity {
public static final String EXTRA_CHARACTERISTIC_UUID = "extra_uuid";
private static final UUID characteristicUuid = UUID.fromString("25A80002-6478-11E6-BDF4");

private PublishSubject<Void> disconnectTriggerSubject = PublishSubject.create();
private Observable<RxBleConnection> connectionObservable;
private RxBleDevice bleDevice;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_example4);
    ButterKnife.bind(this);
    String macAddress = "D5:F8:47:A6:70:0E";
    bleDevice = SampleApplication.getRxBleClient(this).getBleDevice(macAddress);
    connectionObservable = prepareConnectionObservable();
    //noinspection ConstantConditions
    getSupportActionBar().setSubtitle(getString(R.string.mac_address, macAddress));
    Log.i(getClass().getSimpleName(), "onCreate");
    bleDevice.observeConnectionStateChanges().subscribe(state -> {
        Log.i(getClass().getSimpleName(), "" + state.toString());
    });
}

private Observable<RxBleConnection> prepareConnectionObservable() {
    return bleDevice
            .establishConnection(false)
            .takeUntil(disconnectTriggerSubject)
            .compose(new ConnectionSharingAdapter());
}

@OnClick(R.id.connect)
public void connect() {
    connectionObservable.flatMap(RxBleConnection::discoverServices)
            .flatMap(rxBleDeviceServices -> rxBleDeviceServices.getCharacteristic(characteristicUuid))
            .observeOn(AndroidSchedulers.mainThread())
            .doOnSubscribe(() -> Log.i(getClass().getSimpleName(), "start connect "))
            .subscribe(
                    characteristic -> {
                        Log.i(getClass().getSimpleName(), "Hey, connection has been established!");
                    },
                    this::onConnectionFailure,
                    this::onConnectionFinished
            );
    }
}

Actual result

RxBleAdapterStateObservable and DisconnectionRouter is leaked memory. Because broacastReceiver in RxBleAdapterStateObservale is not unregister

Expected result

RxBleAdapterStateObservable and DisconnectionRouter is not leaked memory

@dariuszseweryn
Copy link
Owner

Hello @hoanglm4
Thank you for the report. Apparently there was an issue with DisconnectionRouter that prevented the RxBleAdapterStateObservable from being unsubscribed. It should now be fixed with #353 .
You can check out 1.5.0-SNAPSHOT if that is the case.
Best Regards

@dariuszseweryn dariuszseweryn self-assigned this Jan 8, 2018
@dariuszseweryn dariuszseweryn added the bug Bug that is caused by the library label Jan 8, 2018
@dariuszseweryn dariuszseweryn added this to the 1.5.0 milestone Jan 8, 2018
@hoanglm4
Copy link
Author

hoanglm4 commented Jan 8, 2018

Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug that is caused by the library
Projects
None yet
Development

No branches or pull requests

2 participants