我是靠谱客的博主 土豪煎饼,最近开发中收集的这篇文章主要介绍解决“java.lang.OutOfMemoryError: Failed to allocate a allocation until OOM”错误,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
1.参考:解决“java.lang.OutOfMemoryError: Failed to allocate a allocation until OOM”错误_SEVENY_的博客-CSDN博客
“java.lang.OutOfMemoryError: Failed to allocate a allocation until OOM”内存溢出错误是在Android app运行的时候出现的,这可能是因为app RAM中缓存太多文件或反复实例化相同的位图和视频造成的内存不足现象,下面是我在运行时候所出现的错误。
java.lang.OutOfMemoryError: Failed to allocate a 29859852 byte allocation with 3827656 free bytes and 3MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1080)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2635)
at android.content.res.Resources.loadDrawable(Resources.java:2540)
at android.content.res.TypedArray.getDrawable(TypedArray.java:870)
at android.widget.ImageView.<init>(ImageView.java:152)
at android.widget.ImageView.<init>(ImageView.java:140)
at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java:74)
at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java:69)
at androidx.appcompat.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java:199)
at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:119)
at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1551)
at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1602)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:189)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:746)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at com.example.animationhome.fragment.MainRecommendFragment5.onCreateView(MainRecommendFragment5.java:43)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2600)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:881)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1238)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:434)
at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManagerImpl.java:2079)
at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1869)
at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1824)
at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManagerImpl.java:1727)
at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManagerImpl.java:2663)
at androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManagerImpl.java:2613)
at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:246)
at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:542)
at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:210)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1237)
at android.app.Activity.performStart(Activity.java:6296)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java
可以在androidmenifest.xml文件中更改application配置,将hardwareAccelerated设置为false,largeHeap设置为true。
android:largeHeap = "true" android:hardwareAccelerated = "false" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme">
android:hardwareAccelerated = "true"的时候会牺牲内存来加快图片的加载速度。
android:largeHeap = "false"会限制app应用申请的内存大小。
最后
以上就是土豪煎饼为你收集整理的解决“java.lang.OutOfMemoryError: Failed to allocate a allocation until OOM”错误的全部内容,希望文章能够帮你解决解决“java.lang.OutOfMemoryError: Failed to allocate a allocation until OOM”错误所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复