Android 内存不足错误,外部内存
我创建了一个具有 Android 2.2 内核和最大 VM 堆大小 =24Mb
的模拟器。当活动在其上运行时,logcat 显示内存不足错误:
"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之前,图像的像素数据存储在中>“本机记忆”。 “本机内存”与“外部内存”相同吗?
I created an emulator with Android 2.2 kernel and max VM heap size =24Mb
. When an activity runs on it, the logcat show outofmemory error:
"861984-byte external allocation too larger for this process"
Can I know what does "external allocation" here mean? Is this the "external memory"? This activity call setContentView(R.layout.main)
.
The layout 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>
The dimension of image splash.png is 640*960
Before Honeycomb, pixel data of image was stored in "native memory". Is "native memory" the same as "external memory"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
每次加载新图像时将 imageview 设置为 null。或者每次加载新图像时对 imageview 对象使用 recycle() 方法
set your imageview to null each time when you load the new image.Or use recycle() method to your imageview object each time when you load the new image
阅读本文。我通过创建自己的主题(使用平铺的可绘制对象)解决了
setContentView
调用中的内存问题,而不是使用默认的 Android 主题,然后将大图像设置为背景,这导致重新绘制布局,这是浪费的内存和 CPU 性能。Read this. I solved my memory issue in the
setContentView
call by creating my own theme (using a tiled drawable) rather than using a default Android theme then setting a large image as background that caused redrawing of the layout which is wasteful to both memory and CPU performance.