我是靠谱客的博主 热情纸鹤,最近开发中收集的这篇文章主要介绍java.lang.OutOfMemoryError: Failed to allocate a 84049935 byte allocation with 16777216 free bytes a,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

java.lang.OutOfMemoryError: Failed to allocate a 84049935 byte allocation with 16777216 free bytes and 64MB until OOM
	at okio.Buffer.readByteArray(Buffer.java:861)
	at okio.Buffer.readString(Buffer.java:713)
	at okio.Buffer.readString(Buffer.java:696)
	at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:199)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
	at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:254)
	at okhttp3.RealCall.execute(RealCall.java:92)
	at retrofit2.OkHttpCall.execute(OkHttpCall.java:186)
	at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:41)
	at io.reactivex.Observable.subscribe(Observable.java:12090)
	at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:34)
	at io.reactivex.Observable.subscribe(Observable.java:12090)
	at io.reactivex.internal.operators.flowable.FlowableFromObservable.subscribeActual(FlowableFromObservable.java:29)
	at io.reactivex.Flowable.subscribe(Flowable.java:14479)
	at io.reactivex.internal.operators.flowable.FlowableOnBackpressureLatest.subscribeActual(FlowableOnBackpressureLatest.java:32)
	at io.reactivex.Flowable.subscribe(Flowable.java:14479)
	at io.reactivex.internal.operators.flowable.FlowableFlatMap.subscribeActual(FlowableFlatMap.java:53)
	at io.reactivex.Flowable.subscribe(Flowable.java:14479)
	at io.reactivex.Flowable.subscribe(Flowable.java:14426)
	at io.reactivex.internal.operators.flowable.FlowableSubscribeOn$SubscribeOnSubscriber.run(FlowableSubscribeOn.java:82)
	at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
 Caused by: io.reactivex.exceptions.UndeliverableException: The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the exception has nowhere to go to begin with. Further reading: https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#error-handling | Failed to allocate a 84049935 byte allocation with 16777216 free bytes and 64MB until OOM
	at io.reactivex.plugins.RxJavaPlugins.onError(RxJavaPlugins.java:367)
	at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:69)
	at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
	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)

查询网上说加载大图片导致,需要在清单文件的application中加上下面两行代码:

 android:largeHeap="true"
 android:hardwareAccelerated="false"

但是我这里是由于RxJava异常导致OOM

解决方案:在Application设置RxJavaPlugin的ErrorHandler

/**
* RxJava2 当取消订阅后(dispose()),RxJava抛出的异常后续无法接收(此时后台线程仍在跑,可能会抛出IO等异常),全部由RxJavaPlugin接收,需要提前设置ErrorHandler
     * 详情:http://engineering.rallyhealth.com/mobile/rxjava/reactive/2017/03/15/migrating-to-rxjava-2.html#Error Handling
*/
private void setRxJavaErrorHandler() {
   RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
       @Override
       public void accept(Throwable throwable) throws Exception {
           BLogger.d(TAG, "throw test");
       }
    });
}

最后

以上就是热情纸鹤为你收集整理的java.lang.OutOfMemoryError: Failed to allocate a 84049935 byte allocation with 16777216 free bytes a的全部内容,希望文章能够帮你解决java.lang.OutOfMemoryError: Failed to allocate a 84049935 byte allocation with 16777216 free bytes a所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(31)

评论列表共有 0 条评论

立即
投稿
返回
顶部