title: What is the proper way to handle subscriptions in RxJava/RxAndroid for an Activity Lifecycle?
body: <p>I am just getting started on RxJava/RxAndroid. I want to avoid context leaks so I created a BaseFragment like so:</p>
  
  <pre><code>public abstract class BaseFragment extends Fragment {
  
      protected CompositeSubscription compositeSubscription = new CompositeSubscription();
  
      @Override
      public void onDestroy() {
          super.onDestroy();
  
          compositeSubscription.unsubscribe();
      } 
  } 
  </code></pre>
  
  <p>And inside my fragment that extends BaseFragment, I am doing this: </p>
  
  <pre><code>protected void fetchNewerObjects(){
          if(!areNewerObjectsFetching()){ //if it is not already fetching newer objects
  
              Runtime.getRuntime().gc();//clean out memory if possible
  
              fetchNewObjectsSubscription = Observable
                  .just(new Object1())
                  .map(new Func1&lt;Object1, Object2&gt;() {
                      @Override
                      public Object2 call(Object1 obj1) {
                          //do bg stuff
                          return obj2;
                      }
                  })
                  .subscribeOn(Schedulers.io())
                  .observeOn(AndroidSchedulers.mainThread())
                  .subscribe(new Observer&lt;Object2&gt;() {
                      @Override
                      public void onCompleted() {
                          compositeSubscription.remove(fetchNewObjectsSubscription);
                          fetchNewObjectsSubscription = null;
                      }
  
                      @Override
                      public void onError(Throwable e) {
  
                      }
  
                      @Override
                      public void onNext(ArrayList&lt;NewsFeedObject&gt; newsFeedObjects) {
                          //do stuff
                      }
                  });
  
          //add subscription to composite subscription so it can be unsubscribed onDestroy()
          compositeSubscription.add(fetchNewObjectsSubscription);
      }
  }
  
  protected boolean areNewerObjectsFetching(){
      if(fetchNewObjectsSubscription == null || fetchNewObjectsSubscription.isUnsubscribed()){ //if its either null or is in a finished status
          return false;
      }
      return true;
  }
  </code></pre>
  
  <p>So I guess my question is two-fold: </p>
  
  <ol>
  <li><p>Will this stop context leaks because I am unsubscribing onDestroy()?</p></li>
  <li><p>And am I properly keeping track of wether the observable is "running" by setting the subscription to null after completion and checking the nullity?</p></li>
  </ol>