我有一個使用osmdroid mapactivity的應用程序。在方向更改時出現內存不足錯誤
每當屏幕方向堆大小的增長和後一對夫婦的方向變化,我得到了以下錯誤:
12-12 00:53:08.990: E/dalvikvm-heap(6712): Out of memory on a 262160-byte allocation.
12-12 00:53:08.990: I/dalvikvm(6712): "filesystem" prio=5 tid=46 RUNNABLE
12-12 00:53:08.990: I/dalvikvm(6712): | group="main" sCount=0 dsCount=0 obj=0x43057e08 self=0x571583c8
12-12 00:53:08.990: I/dalvikvm(6712): | sysTid=8674 nice=0 sched=0/0 cgrp=apps handle=1487255264
12-12 00:53:08.990: I/dalvikvm(6712): | schedstat=(298265664 165380214 301) utm=25 stm=4 core=0
12-12 00:53:08.990: I/dalvikvm(6712): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
12-12 00:53:08.995: I/dalvikvm(6712): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:650)
12-12 00:53:08.995: I/dalvikvm(6712): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:389)
12-12 00:53:08.995: I/dalvikvm(6712): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:449)
12-12 00:53:08.995: I/dalvikvm(6712): at org.osmdroid.tileprovider.tilesource.BitmapTileSourceBase.getDrawable(BitmapTileSourceBase.java:93)
12-12 00:53:08.995: I/dalvikvm(6712): at org.osmdroid.tileprovider.modules.MapTileFilesystemProvider$TileLoader.loadTile(MapTileFilesystemProvider.java:142)
12-12 00:53:08.995: I/dalvikvm(6712): at org.osmdroid.tileprovider.modules.MapTileModuleProviderBase$TileLoader.run(MapTileModuleProviderBase.java:241)
12-12 00:53:08.995: I/dalvikvm(6712): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
12-12 00:53:08.995: I/dalvikvm(6712): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
12-12 00:53:08.995: I/dalvikvm(6712): at java.lang.Thread.run(Thread.java:856)
12-12 00:53:09.020: I/dalvikvm-heap(6712): Clamp target GC heap from 64.436MB to 64.000MB
12-12 00:53:09.050: I/dalvikvm-heap(6712): Forcing collection of SoftReferences for 262160-byte allocation
12-12 00:53:09.095: I/dalvikvm-heap(6712): Clamp target GC heap from 64.436MB to 64.000MB
我有擁有兩個片段和這兩個片段延長一個抽象片段的活動這會初始化MapActivity。
我已經閱讀了相同問題的其他人的不少帖子。我最終實現在抽象的片段如下:
@Override
public void onDestroyView() {
super.onDestroyView();
unbindDrawables(con.findViewById(R.id.main_layout));
System.gc();
}
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();
}
}
這裏是我的onCreateView其初始化CON:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
con = container;
return inflater.inflate(R.layout.main_fragment,container, false);
}
我不知道還有什麼我能做的。
任何人都可以幫我解決這個問題嗎?
感謝
你正在你的應用程序中加載一些圖像? – artsylar
您的應用程序中有內存泄漏。安裝MAT http://android-developers.blogspot.pt/2011/03/memory-analysis-for-android.html並檢查哪些引用阻止GC收集對象。 – Luis