title: OutOfMemoryError while downloading large file as byte array using retrofit in android
body: <p>I am using retrofit to download a large file in android.
  The API is returning the file as byte array, I have added the @Streaming annotation as recommmended, however I still getting the error.</p>
  
  <p>What can I do to solve it?</p>
  
  <p>THE ERROR IS OCCURRING DURING DOWNLOAD.</p>
  
  <p>My code:</p>
  
  <pre><code>//Retrofi api method
  @Streaming
  @GET(POOL + "DmListarDocsProjZip/{IdProjetct}")
  Call&lt;byte[]&gt; dmListarDocsProjZip(@Path("IdProjetct") int idProject);
  
  
  //THIS CODE IS INSIDE AN IntentService 
  //consuming method
  private byte[] buscarDocs(int idProjeto) {
      try {
          Call&lt;byte[]&gt; call = mApi.dmListarDocsProjZip(idProject);
          Response&lt;byte[]&gt; response = call.execute();// The OutOfMemoryError is ocurring in here
          return response.body();
  
      } catch (IOException e) {
          Log.e("buscarDocs", "dmListarDocsProjetoZip");
  
      } catch (Exception e) {
          verificarSeSessaoExpirou(e);
      }
  
      return null;
  }
  
  Process: br.gov.sp.prodesp.viafacilbombeiros, PID: 27184
      java.lang.OutOfMemoryError: Failed to allocate a 68706640 byte allocation with 16777120 free bytes and 203MB until OOM
          at java.util.ArrayList.add(ArrayList.java:118)
          at com.google.gson.internal.bind.ArrayTypeAdapter.read(ArrayTypeAdapter.java:73)
          at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:37)
          at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:25)
          at retrofit2.ServiceMethod.toResponse(ServiceMethod.java:117)
          at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:211)
          at retrofit2.OkHttpCall.execute(OkHttpCall.java:174)
          at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall.execute(ExecutorCallAdapterFactory.java:89)
          at br.gov.sp.prodesp.viafacilbombeiros.model.DownloadDadosIntentService.buscarDocs(DownloadDadosIntentService.java:253)
          at br.gov.sp.prodesp.viafacilbombeiros.model.DownloadDadosIntentService.access$300(DownloadDadosIntentService.java:61)
          at br.gov.sp.prodesp.viafacilbombeiros.model.DownloadDadosIntentService$1.onNext(DownloadDadosIntentService.java:215)
          at br.gov.sp.prodesp.viafacilbombeiros.model.DownloadDadosIntentService$1.onNext(DownloadDadosIntentService.java:189)
          at rx.observers.SafeSubscriber.onNext(SafeSubscriber.java:139)
          at retrofit2.adapter.rxjava.OperatorMapResponseToBodyOrError$1.onNext(OperatorMapResponseToBodyOrError.java:41)
          at retrofit2.adapter.rxjava.OperatorMapResponseToBodyOrError$1.onNext(OperatorMapResponseToBodyOrError.java:38)
          at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$RequestArbiter.request(RxJavaCallAdapterFactory.java:173)
          at rx.Subscriber.setProducer(Subscriber.java:209)
          at rx.Subscriber.setProducer(Subscriber.java:205)
          at rx.Subscriber.setProducer(Subscriber.java:205)
          at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:152)
          at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:138)
          at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:50)
          at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
          at rx.Observable.subscribe(Observable.java:8553)
          at rx.Observable.subscribe(Observable.java:8520)
          at br.gov.sp.prodesp.viafacilbombeiros.model.DownloadDadosIntentService.onHandleIntent(DownloadDadosIntentService.java:124)
          at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:145)
          at android.os.HandlerThread.run(HandlerThread.java:61)
  </code></pre>