Android Outofmemory错误,外部内存

时间:2011-08-18 03:21:24

标签: android out-of-memory

我创建了一个带有 Android 2.2 内核和最大VM堆大小= 24Mb的模拟器。当活动在其上运行时,logcat会显示outofmemory错误:

"861984-byte external allocation too larger for this process"

我能知道“外部分配”在这里意味着什么吗?这是“外部记忆”吗?此活动会致电setContentView(R.layout.main)

布局main.xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/login_bg"
>
<ImageView  
android:layout_width="190dp" 
android:layout_height="50dp" 
android:scaleType = "fitXY"
android:layout_gravity="center"
android:src="@drawable/login_btn_fb"
android:id="@+id/facebookconnect"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility = "visible"
android:src="@drawable/splash"
android:scaleType = "fitXY"
android:id="@+id/splashscreen"
/>
</FrameLayout>

图片 splash.png 的尺寸为640*960

Honeycomb 之前,图像的像素数据存储在“native memory”中。 “本机内存”“外部内存”相同吗?

2 个答案:

答案 0 :(得分:3)

每次加载新图像时,

将imageview设置为null。每次加载新图像时,都会对imageview对象使用recycle()方法

答案 1 :(得分:0)

阅读this。通过创建我自己的主题(使用平铺的drawable)而不是使用默认的Android主题,然后将大图像设置为背景导致重新布局布局,这对于内存都是浪费,我在setContentView调用中解决了我的内存问题和CPU性能。