Skip to content
This repository has been archived by the owner on Mar 16, 2021. It is now read-only.

Use of compose(RxTiPresenterUtils.deliverLatestCacheToView(this)) creates too many instances of OperatorSemaphore #28

Open
ar-g opened this issue Oct 27, 2016 · 0 comments

Comments

@ar-g
Copy link

ar-g commented Oct 27, 2016

When using your lib, I noticed weird side-effect, when using

compose(RxTiPresenterUtils.deliverLatestCacheToView(this))

it creates too many instances of OperatorSemaphore. After config changes and moving between screens with "Don't Keep Activities" flag. I tried to trigger GC, but it didn't help.

screenshot from 2016-10-26 15-56-24

On the opposite side using

compose(RxTiPresenterUtils.deliverToView(this))

worked just fine. Firstly, it didn't create so many instances, secondly, after triggering GC, the existing instances of OperatorSemaphore was destroyed.

I did look into the internals of caching version it seemed to me that after presenter is destroyed lifecycle observers should be removed therefore triggering GC should clear OperatorSemaphore instances.

Can you better explain how it should work, and when GC should clear out those instances.

Couple of unrelated questions

  1. Should deliverLatestCacheToView propagate cached Error?
  2. Any actions with view in doOnSubscribe/doOnTerminate will crash the app when user will leave and go back to view during network request. I expect isViewReady(presenter) will emit items and deliver cache only when view fully attached.

Full code

  @Override protected void onWakeUp() {
    super.onWakeUp();

    loadChats();
  }

  public void loadChats() {
    rxSubscriptionHelper.manageSubscription(
        chatOperations.getChats(chatType)
            .observeOn(AndroidSchedulers.mainThread())
            .doOnSubscribe(() -> {
              if (getView() != null) {
                getView().showRefreshing();
              }
            })
            .doOnTerminate(() -> {
              if (getView() != null) {
                getView().stopRefresginAndHideMsgs();
              }
            })

            .compose(RxTiPresenterUtils.deliverLatestCacheToView(this))
            .subscribe(chats -> {
              getView().setChats(chats);
            }, e -> {
              if (e instanceof RxNetworkException) {
                getView().stopRefreshAndShowError(e.getMessage());
              } else {
                throw new RuntimeException(e);
              }
            })
    );
  }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants