I have an app which uses an osmdroid mapactivity.
Every time the screen orientation the heap size grows and after a couple of orientation changes I get the following errors:
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
I have an Activity which holds two fragments and both of those fragments extend one abstract fragment which initialises the MapActivity.
I have read quite a few posts from other people with the same problem. I ended up implementing the following in the abstract Fragment:
@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();
}
}
Here is my onCreateView which initialises con:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
con = container;
return inflater.inflate(R.layout.main_fragment,container, false);
}
I am not sure what else I can do.
can anyone help me solve this?
Thanks
Try handling the screen rotation yourself, add the following code into the activity
and add the following into your activity tag in your manifest file
android:configChanges=”orientation|keyboardHidden|screenSize”