title: Rxjava + Retrofit Throwing OutOfMemoryError
body: <p>When I use Retrofit with rxjava, some machine throwing OOM, this is log:</p>
  
  <pre><code>java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.
  at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:59)
  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
  at java.util.concurrent.FutureTask.run(FutureTask.java:237)
  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
  at java.lang.Thread.run(Thread.java:818)
  Caused by: java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Try again
  at java.lang.Thread.nativeCreate(Native Method)
  at java.lang.Thread.start(Thread.java:1063)
  at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:920)
  at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1338)
  at okhttp3.ConnectionPool.put(ConnectionPool.java:135)
  at okhttp3.OkHttpClient$1.put(OkHttpClient.java:149)
  at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:188)
  at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:129)
  at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:98)
  at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
  at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:109)
  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
  at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
  at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:124)
  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
  at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:145)
  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
  at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:170)
  at okhttp3.RealCall.execute(RealCall.java:60)
  at retrofit2.OkHttpCall.execute(OkHttpCall.java:174)
  at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$RequestArbiter.request(RxJavaCallAdapterFactory.java:171)
  at rx.internal.operators.OperatorSubscribeOn$1$1$1.request(OperatorSubscribeOn.java:80)
  at rx.Subscriber.setProducer(Subscriber.java:209)
  at rx.internal.operators.OperatorSubscribeOn$1$1.setProducer(OperatorSubscribeOn.java:76)
  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:48)
  at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
  at rx.Observable.unsafeSubscribe(Observable.java:9861)
  at rx.internal.operators.OperatorSubscribeOn$1.call(OperatorSubscribeOn.java:94)
  at rx.internal.schedulers.CachedThreadScheduler$EventLoopWorker$1.call(CachedThreadScheduler.java:221)
  at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422) 
  at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152) 
  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265) 
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
  at java.lang.Thread.run(Thread.java:818) 
  </code></pre>
  
  <p>my retrofit code:</p>
  
  <pre><code>  HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
      if (BuildConfig.LOG_DEBUG)
          interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
      else
          interceptor.setLevel(HttpLoggingInterceptor.Level.NONE);
      OkHttpClient client = new OkHttpClient.Builder()
              .addInterceptor(interceptor)
              .retryOnConnectionFailure(true)
              .connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
              .readTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
              .build();
  
      retrofit = new Retrofit.Builder()
              .baseUrl(ConstantValue.URL + "/")
              .client(client)
              .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
              .build();
  </code></pre>
  
  <p>and my request code:</p>
  
  <pre><code>public interface GetUserFriendUsersService {
  
  @FormUrlEncoded
  @POST("IM/GetUserFriendUsers")
  Observable&lt;ResponseBody&gt; getUserFriendUsers(@Field("UserID")String UserID);}
  
   public void getUserFriendUsers(String userID, Subscriber&lt;List&lt;Users&gt;&gt; subscriber) {
      retrofit.create(GetUserFriendUsersService.class)
              .getUserFriendUsers(userID)
              .subscribeOn(Schedulers.io())
              .unsubscribeOn(Schedulers.io())
              .map(new HttpResultFunc())
              .map(new Func1&lt;JSONObject, List&lt;Users&gt;&gt;() {
                  @Override
                  public List&lt;Users&gt; call(JSONObject jsonObject) {
                      List&lt;Users&gt; users = JSON.parseArray(jsonObject.getString("users"), Users.class);
                      if (users.size() == 0)
                          throw new CustomizeException("no data");
                      return users;
                  }
              })
              .observeOn(AndroidSchedulers.mainThread())
              .subscribe(subscriber);
  }
  </code></pre>