gpt4 book ai didi

android - dalvikvm 堆 : Out of memory on a 73547536-byte allocation

转载 作者:太空宇宙 更新时间:2023-11-03 12:10:29 25 4
gpt4 key购买 nike

我已经释放了每个对象,回收了 onDestroy() 方法中的所有位图:

     private void unbindDrawables(View view) {
if (view.getBackground() != null) {
view.getBackground().setCallback(null);
}
if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
unbindDrawables(((ViewGroup) view).getChildAt(i));
}
((ViewGroup) view).removeAllViews();
}
}
@Override
protected void onDestroy()
{
super.onDestroy();
unbindDrawables(findViewById(R.id.RootView));
bitmap.recycle();
bitmap=null;
System.gc();

}

我在每个类的 onDestroy() 方法中都完成了这个编码。但我的 logcat 仍然向我显示如下错误:

            FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{}: android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.RelativeLayout
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
android.app.ActivityThread.access$600(ActivityThread.java:123)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
android.os.Handler.dispatchMessage(Handler.java:99)
android.os.Looper.loop(Looper.java:137)
android.app.ActivityThread.main(ActivityThread.java:4424)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.RelativeLayout
android.view.LayoutInflater.createView(LayoutInflater.java:606)
com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
android.view.LayoutInflater.inflate(LayoutInflater.java:466)
android.view.LayoutInflater.inflate(LayoutInflater.java:396)
android.view.LayoutInflater.inflate(LayoutInflater.java:352)
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
android.app.Activity.setContentView(Activity.java:1835)
android.app.Activity.performCreate(Activity.java:4465)
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
java.lang.reflect.Constructor.constructNative(Native Method)
java.lang.reflect.Constructor.newInstance(Constructor.java:417)
android.view.LayoutInflater.createView(LayoutInflater.java:586)
... 23 more
Caused by: java.lang.OutOfMemoryError
android.graphics.Bitmap.nativeCreate(Native Method)
android.graphics.Bitmap.createBitmap(Bitmap.java:605)
android.graphics.Bitmap.createBitmap(Bitmap.java:551)
android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437)
android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:524)
android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:499)
android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
android.content.res.Resources.loadDrawable(Resources.java:1935)
android.content.res.TypedArray.getDrawable(TypedArray.java:601)
android.view.View.<init>(View.java:2785)
android.view.View.<init>(View.java:2722)
android.view.ViewGroup.<init>(ViewGroup.java:379)
android.widget.RelativeLayout.<init>(RelativeLayout.java:174)
... 26 more

最佳答案

标题说明了一切——您正试图一次为一张图像分配 73 兆字节 的堆。仅此一项就超过了大多数现代设备上可用的堆大小——64 兆字节。您需要找到一种方法来使用明显更小的图像。

关于android - dalvikvm 堆 : Out of memory on a 73547536-byte allocation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12367874/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com