【发布时间】:2014-01-18 11:07:25
【问题描述】:
我试图弄清楚为什么我的应用程序的位图(仅在 xml 布局中使用)永远不会被回收,所以在用户浏览 10/12 页面后,应用程序崩溃并出现内存不足异常。
我尝试使用 Mat 分析内存使用情况,我可以在 Retained Heap 中找到每个位图。
以下是图像在 XML 布局中的使用方式(每个布局大约 1 个):
<ImageView
android:id="@+id/imageView"
android:layout_width="fill_parent"
android:layout_height="2000dp"
android:scaleType="fitStart"
android:src="@drawable/welcome"/>
这里是相关的活动代码:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
ImageView but = (ImageView)findViewById(R.id.imageView2);
View.OnClickListener listener = new View.OnClickListener()
{
public void onClick(View view)
{
Intent myIntent = new Intent(view.getContext(), EtaActivity.class);
startActivity(myIntent);
overridePendingTransition(0,0);
finish();
}
};
but.setOnClickListener(listener);
}
public void onDestroy()
{
super.onDestroy();
}
有什么想法吗?
【问题讨论】:
标签: android memory-leaks bitmap garbage-collection