Retrofit v2 Does Call.cancel() remove Callback? : <p>I've read in the <a href="https://github.com/square/retrofit/issues/297" rel="noreferrer">Retrofit v2 API Spec</a> that calling the cancel() method on the Call class returned from your custom retrofit interface should set the Callback passed in to null.</p>

<blockquote>
  <p>cancel() is a no-op after the response has been received. In all other
  cases the method will set any callbacks to null (thus freeing strong
  references to the enclosing class if declared anonymously)</p>
</blockquote>

<p>Going through the code I can't see that the Callback is explicitly set to null when cancel is called. I can see the callback being referenced in the <a href="https://github.com/square/retrofit/blob/6269b91f2d7436c6afed47fb5f2be80c566f412a/retrofit/src/main/java/retrofit2/OkHttpCall.java" rel="noreferrer">OkHttpCall</a> class (although not explicitly stored). Calling cancel will in turn call cancel on the RealCall class which takes care of the Http side of canceling, but does not concern itself with the stored callback in the AsyncCall class (which is put in the readyAsyncCalls and runningAsyncCalls queues in the Dispatcher class. It is unfamiliar code to me so I might be missing something.</p>

<p>Can someone confidently confirm that calling cancel() on my call object will remove reference to the Callback I've passed in so I don't leak memory?</p>

<p>Simplified code example:</p>

<pre><code>@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .build();
    api = retrofit.create(Api.class);
}

@Override
public void onStart() {
    super.onStart();
    call = api.getPokedex();
    call.enqueue(new Callback&lt;Pokedex&gt;() {
        @Override
        public void onResponse(Call&lt;Pokedex&gt; call, Response&lt;Pokedex&gt; response) {
            populate(response.body());
        }

        @Override
        public void onFailure(Call&lt;Pokedex&gt; call, Throwable t) {
            error(t.getMessage());
        }
    });
}

@Override
public void onStop() {
    call.cancel();
    super.onStop();
}
</code></pre>
