Arello-Mobile / Moxy

Moxy is MVP library for Android
https://github.com/Arello-Mobile/Moxy/wiki
MIT License
1.61k stars 207 forks source link

ViewState memory issue #96

Closed ghost closed 7 years ago

ghost commented 7 years ago

Hi,

I am using Rx java to get List from datastore and pass it to ViewState. When I repeat this action old List keeps alive in a memory (I suppose in ViewState was created strong reference). Is it normal behavior for Moxy?

        getFeedItemsUseCase.perform(feedId)
                           .subscribeOn(Schedulers.io())
                           .observeOn(AndroidSchedulers.mainThread())
                           .subscribe(feedItems -> {
                               getViewState().setupFeedsItems(feedItems, 0);
                           });

Activity has empty realization of the interface.

    @StateStrategyType(AddToEndSingleStrategy.class)
    void setupFeedsItems(List<? extends FeedItem> feedItems, int position);

If wrap a List with WeakReference it will be removed from memory.

    @StateStrategyType(AddToEndSingleStrategy.class)
    void setupFeedsItems(WeakReference<List<? extends FeedItem>> feedItems, int position);

I am using:

    compile 'io.reactivex.rxjava2:rxandroid:2.0.0'
    compile 'io.reactivex.rxjava2:rxjava:2.0.0'

    compile 'com.arello-mobile:moxy-app-compat:1.4.5'
    annotationProcessor 'com.arello-mobile:moxy-compiler:1.4.5'
senneco commented 7 years ago

Well, feedItems will be kept while setupFeedsItems command contains in ViewState