Hello,
i have a problem with a strange out of memory exception that only occurs on some devices (mostly HTC Desire). It happens there every time a user starts a certain activity (no matter how - there are two paths to that activity) and i'm really puzzled as to why (i checked for leaks and couldn't find any)...
The error is either thrown when calling setContentView or shortly after.
This is the code block that throws the error:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(DebugFlags.LOG_MEMORY)
{
MemoryAnalyser.logHeap(this.getClass());
}
setContentView(R.layout.activity_stats);
try
{
monthsAvailable = getMonthTimeStamps();
Spinner xSpin = (Spinner) findViewById(R.id.spinnerTimespan);
m_adapterForSpinner = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item);
m_adapterForSpinner.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
xSpin.setAdapter(m_adapterForSpinner);
for(Iterator<monthObject> i = monthsAvailable.iterator();i.hasNext();)
{
monthObject xObj = i.next();
String dateString = String.format("%1$te.%1$tm.%1$tY - %2$te.%2$tm.%2$tY", xObj.fromDate, xObj.toDate);
m_adapterForSpinner.add(dateString);
}
xSpin.setSelection(xSpin.getCount()-1);
xSpin.setOnItemSelectedListener(this);
//setupStatData(null, null);
checkStatsAvailable();
//throw(new java.lang.OutOfMemoryError());
}
catch(java.lang.OutOfMemoryError e)
{
MemoryAnalyser.dumpHeap();
MemoryAnalyser.logHeap(this.getClass());
Toast xToast = Toast.makeText(getApplicationContext(), "OutOfMemoryException - bitte Log und Datei com.eventkontor.networkcheck.hprof auf SD-Karte an Entwickler senden", 5000);
xToast.show();
this.finish();
}
if(DebugFlags.LOG_MEMORY)
{
MemoryAnalyser.logHeap(this.getClass());
}
}
as i said - the error is usually thrown when calling setContentView or when calling getMonthTimeStamps()
getMonthTimeStamps is a helper function which creates a list of dates available in the internal database. It creates a couple of (small objects) and returns an ArrayList. Here is the function
private ArrayList<monthObject> getMonthTimeStamps()
{
ArrayList<monthObject> dates = new ArrayList<monthObject>();
Cursor c = getContentResolver().query(CallLogTableMetaData.CONTENT_URI, new String[]{CallLogTableMetaData.CALLOG_DATE}, null, null, CallLogTableMetaData._ID + " asc");
try{
if(c.moveToFirst())
{
SharedPreferences prefs = Utils.getPreferences(this);
int resetDay = prefs.getInt("pref_callog_reset_day", 1);
prefs = null;
long starttime = c.getLong(0);
c.close();
c=null;
Date startDate = new Date(starttime);
GregorianCalendar today = new GregorianCalendar();
GregorianCalendar xCal = new GregorianCalendar();
xCal.setTime(startDate);
xCal.set(GregorianCalendar.DAY_OF_MONTH, resetDay);
while(xCal.before(today))
{
monthObject xObj = new monthObject();
xObj.setTimestamp(xCal.getTimeInMillis());
xObj.setFromDate(xCal.getTime());
xCal.add(GregorianCalendar.MONTH, 1);
xCal.set(GregorianCalendar.DAY_OF_MONTH, resetDay);
xCal.set(Calendar.HOUR_OF_DAY, 0);
xCal.set(Calendar.MINUTE, 0);
xCal.set(Calendar.SECOND, 0);
xCal.set(Calendar.MILLISECOND, 0);
xObj.setToDate(xCal.getTime());
xObj.setToTimestamp(xCal.getTimeInMillis());
dates.add(xObj);
xObj = null;
}
xCal = null;
today = null;
return dates;
}
else
{
return dates;
}
}
finally{
try
{
c.close();
}
catch(Exception e)
{
}
}
}
I'm not claiming that my code is flawless or perfect, but i really don't understand why this error is thrown. The XML-layout doesn't contain any references to images and not very complicated (textview, spinner, tablelayout).
Here is the error log i received from one user:
I/ActivityManager(16789): Starting activity: Intent { cmp=com.eventkontor.networkcheck/.StatActivity }
D/dalvikvm( 5053): GC freed 8267 objects / 556152 bytes in 45ms
D/dalvikvm( 5053): GC freed 1716 objects / 371240 bytes in 45ms
D/dalvikvm( 5053): GC freed 15 objects / 62936 bytes in 56ms
D/dalvikvm( 5053): GC freed 4 objects / 233856 bytes in 77ms
D/dalvikvm( 5053): GC freed 14 objects / 544 bytes in 83ms
W/ActivityManager(16789): Launch timeout has expired, giving up wake lock!
W/ActivityManager(16789): Activity idle timeout for HistoryRecord{46a4b878 com.eventkontor.networkcheck/.StatActivity}
D/dalvikvm( 5053): GC freed 3 objects / 210456 bytes in 107ms
D/dalvikvm( 5053): GC freed 3 objects / 315656 bytes in 118ms
D/dalvikvm( 5210): GC freed 7752 objects / 904320 bytes in 1116ms
D/dalvikvm( 5053): GC freed 2 objects / 48 bytes in 136ms
D/dalvikvm( 5053): GC freed 3 objects / 473448 bytes in 155ms
D/dalvikvm( 641): GC freed 4397 objects / 781024 bytes in 1246ms
D/dalvikvm( 5053): GC freed 2 objects / 48 bytes in 175ms
D/dalvikvm( 5053): GC freed 2 objects / 56 bytes in 203ms
I/dalvikvm-heap( 5053): Clamp target GC heap from 24.522MB to 24.000MB
D/dalvikvm( 5053): GC freed 3 objects / 710120 bytes in 207ms
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.012MB to 24.000MB
D/dalvikvm( 5053): GC freed 2 objects / 56 bytes in 220ms
I/dalvikvm-heap( 5053): Clamp target GC heap from 24.012MB to 24.000MB
I/dalvikvm-heap( 5053): Grow heap (frag case) to 24.000MB for 16-byte allocation
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.012MB to 24.000MB
D/dalvikvm( 5053): GC freed 0 objects / 0 bytes in 238ms
I/dalvikvm-heap( 5053): Forcing collection of SoftReferences for 24-byte allocation
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.012MB to 24.000MB
D/dalvikvm( 5053): GC freed 0 objects / 0 bytes in 220ms
E/dalvikvm-heap( 5053): Out of memory on a 24-byte allocation.
I/dalvikvm( 5053): "HeapWorker" daemon prio=5 tid=5 RUNNABLE
I/dalvikvm( 5053): | group="system" sCount=0 dsCount=0 s=N obj=0x44e0eab8 self=0x14a298
I/dalvikvm( 5053): | sysTid=5054 nice=0 sched=0/0 cgrp=default handle=1351480
I/dalvikvm( 5053): at com.android.internal.os.BinderInternal$GcWatcher.finalize(BinderInternal.java:~48)
I/dalvikvm( 5053): at dalvik.system.NativeStart.run(Native Method)
I/dalvikvm( 5053):
E/dalvikvm( 5053): Out of memory: Heap Size=22791KB, Allocated=22204KB, Bitmap Size=1806KB
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.012MB to 24.000MB
D/dalvikvm( 5053): GC freed 0 objects / 0 bytes in 291ms
I/dalvikvm-heap( 5053): Forcing collection of SoftReferences for 40-byte allocation
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.012MB to 24.000MB
D/dalvikvm( 5053): GC freed 0 objects / 0 bytes in 220ms
E/dalvikvm-heap( 5053): Out of memory on a 40-byte allocation.
I/dalvikvm( 5053): "main" prio=5 tid=3 RUNNABLE
I/dalvikvm( 5053): | group="main" sCount=0 dsCount=0 s=N obj=0x4001b470 self=0xbdd0
I/dalvikvm( 5053): | sysTid=5053 nice=0 sched=0/0 cgrp=default handle=-1343993180
I/dalvikvm( 5053): at com.eventkontor.networkcheck.StatActivity.getMonthTimeStamps(StatActivity.java:~270)
I/dalvikvm( 5053): at com.eventkontor.networkcheck.StatActivity.onCreate(StatActivity.java:119)
I/dalvikvm( 5053): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
I/dalvikvm( 5053): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2544)
I/dalvikvm( 5053): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621)
I/dalvikvm( 5053): at android.app.ActivityThread.access$2200(ActivityThread.java:126)
I/dalvikvm( 5053): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
I/dalvikvm( 5053): at android.os.Handler.dispatchMessage(Handler.java:99)
I/dalvikvm( 5053): at android.os.Looper.loop(Looper.java:123)
I/dalvikvm( 5053): at android.app.ActivityThread.main(ActivityThread.java:4595)
I/dalvikvm( 5053): at java.lang.reflect.Method.invokeNative(Native Method)
I/dalvikvm( 5053): at java.lang.reflect.Method.invoke(Method.java:521)
I/dalvikvm( 5053): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
I/dalvikvm( 5053): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
I/dalvikvm( 5053): at dalvik.system.NativeStart.main(Native Method)
I/dalvikvm( 5053):
E/dalvikvm( 5053): Out of memory: Heap Size=22791KB, Allocated=22204KB, Bitmap Size=1806KB
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.012MB to 24.000MB
D/dalvikvm( 5053): GC freed 0 objects / 0 bytes in 231ms
I/dalvikvm-heap( 5053): Forcing collection of SoftReferences for 24-byte allocation
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.012MB to 24.000MB
D/dalvikvm( 5053): GC freed 0 objects / 0 bytes in 220ms
E/dalvikvm-heap( 5053): Out of memory on a 24-byte allocation.
I/dalvikvm( 5053): "HeapWorker" daemon prio=5 tid=5 RUNNABLE
I/dalvikvm( 5053): | group="system" sCount=0 dsCount=0 s=N obj=0x44e0eab8 self=0x14a298
I/dalvikvm( 5053): | sysTid=5054 nice=0 sched=0/0 cgrp=default handle=1351480
I/dalvikvm( 5053): at com.android.internal.os.BinderInternal$GcWatcher.finalize(BinderInternal.java:~48)
I/dalvikvm( 5053): at dalvik.system.NativeStart.run(Native Method)
I/dalvikvm( 5053):
E/dalvikvm( 5053): Out of memory: Heap Size=22791KB, Allocated=22204KB, Bitmap Size=1806KB
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.012MB to 24.000MB
I/dalvikvm( 5053): Uncaught exception thrown by finalizer (will be discarded):
I/dalvikvm( 5053): Ljava/lang/OutOfMemoryError;: [memory exhausted]
I/dalvikvm( 5053): at dalvik.system.NativeStart.main(Native Method)
D/dalvikvm( 5053): GC freed 0 objects / 0 bytes in 237ms
I/dalvikvm-heap( 5053): Forcing collection of SoftReferences for 24-byte allocation
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.012MB to 24.000MB
D/dalvikvm( 5053): GC freed 1 objects / 16 bytes in 220ms
E/dalvikvm-heap( 5053): Out of memory on a 24-byte allocation.
I/dalvikvm( 5053): "main" prio=5 tid=3 RUNNABLE
I/dalvikvm( 5053): | group="main" sCount=0 dsCount=0 s=N obj=0x4001b470 self=0xbdd0
I/dalvikvm( 5053): | sysTid=5053 nice=0 sched=0/0 cgrp=default handle=-1343993180
I/dalvikvm( 5053): at com.eventkontor.networkcheck.StatActivity.getMonthTimeStamps(StatActivity.java:~270)
I/dalvikvm( 5053): at com.eventkontor.networkcheck.StatActivity.onCreate(StatActivity.java:119)
I/dalvikvm( 5053): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
I/dalvikvm( 5053): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2544)
I/dalvikvm( 5053): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621)
I/dalvikvm( 5053): at android.app.ActivityThread.access$2200(ActivityThread.java:126)
I/dalvikvm( 5053): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
I/dalvikvm( 5053): at android.os.Handler.dispatchMessage(Handler.java:99)
I/dalvikvm( 5053): at android.os.Looper.loop(Looper.java:123)
I/dalvikvm( 5053): at android.app.ActivityThread.main(ActivityThread.java:4595)
I/dalvikvm( 5053): at java.lang.reflect.Method.invokeNative(Native Method)
I/dalvikvm( 5053): at java.lang.reflect.Method.invoke(Method.java:521)
I/dalvikvm( 5053): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
I/dalvikvm( 5053): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
I/dalvikvm( 5053): at dalvik.system.NativeStart.main(Native Method)
I/dalvikvm( 5053):
E/dalvikvm( 5053): Out of memory: Heap Size=22791KB, Allocated=22204KB, Bitmap Size=1806KB
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.011MB to 24.000MB
D/dalvikvm( 5053): GC freed 11 objects / 728 bytes in 221ms
I/dalvikvm-heap( 5053): Clamp target GC heap from 24.011MB to 24.000MB
I/dalvikvm-heap( 5053): Grow heap (frag case) to 24.000MB for 24-byte allocation
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.011MB to 24.000MB
D/dalvikvm( 5053): GC freed 0 objects / 0 bytes in 221ms
I/dalvikvm-heap( 5053): Clamp target GC heap from 24.011MB to 24.000MB
I/dalvikvm-heap( 5053): Grow heap (frag case) to 24.000MB for 136-byte allocation
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.011MB to 24.000MB
D/dalvikvm( 5053): GC freed 0 objects / 0 bytes in 219ms
I/dalvikvm-heap( 5053): Clamp target GC heap from 24.011MB to 24.000MB
I/dalvikvm-heap( 5053): Grow heap (frag case) to 24.000MB for 24-byte allocation
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.011MB to 24.000MB
D/dalvikvm( 5053): GC freed 0 objects / 0 bytes in 220ms
I/dalvikvm-heap( 5053): Clamp target GC heap from 24.011MB to 24.000MB
I/dalvikvm-heap( 5053): Grow heap (frag case) to 24.000MB for 54-byte allocation
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.011MB to 24.000MB
D/dalvikvm( 5053): GC freed 4 objects / 272 bytes in 221ms
I/dalvikvm-heap( 5053): Clamp target GC heap from 24.011MB to 24.000MB
I/dalvikvm-heap( 5053): Grow heap (frag case) to 24.000MB for 24-byte allocation
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.011MB to 24.000MB
D/dalvikvm( 5053): GC freed 0 objects / 0 bytes in 240ms
I/dalvikvm-heap( 5053): Clamp target GC heap from 24.011MB to 24.000MB
I/dalvikvm-heap( 5053): Grow heap (frag case) to 24.000MB for 68-byte allocation
D/dalvikvm( 5053): GC freed 589340 objects / 19930400 bytes in 180ms
I/dalvikvm( 5053): hprof: dumping VM heap to "/sdcard/com.eventkontor.networkcheck.hprof-hptemp".
I/dalvikvm( 5053): hprof: dumping heap strings to "/sdcard/com.eventkontor.networkcheck.hprof".
I/dalvikvm( 5053): hprof: heap dump completed, temp file removed
D/dalvikvm( 5053): GC freed 8 objects / 616 bytes in 1056ms
D/NetworkCheck( 5053): debug. =================================
D/NetworkCheck( 5053): debug.heap native: allocated 5,81MB of 6,94MB (0,61MB free) in [com.eventkontor.networkcheck.StatActivity]
D/NetworkCheck( 5053): debug.memory: allocated: 22,00MB of 24,00MB (19,00MB free)
D/dalvikvm( 5053): GC freed 148 objects / 7608 bytes in 34ms
D/dalvikvm( 5053): GC freed 5 objects / 264 bytes in 33ms
E/dalvikvm-heap( 5053): 32980-byte external allocation too large for this process.
E/dalvikvm( 5053): Out of memory: Heap Size=22791KB, Allocated=2743KB, Bitmap Size=1806KB
E/ ( 5053): VM won't let us allocate 32980 bytes
D/skia ( 5053): --- decoder->decode returned false
D/AndroidRuntime( 5053): Shutting down VM
W/dalvikvm( 5053): threadid=3: thread exiting with uncaught exception (group=0x4001b390)
D/UNHANDLED_EXCEPTION( 5053): Writing unhandled exception to: /data/data/com.eventkontor.networkcheck/files/1.5-55980.stacktrace
I/global ( 5053): Default buffer size used in BufferedWriter constructor. It would be better to be explicit if an 8k-char buffer is required.
D/UNHANDLED_EXCEPTION( 5053): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.eventkontor.networkcheck/com.eventkontor.networkcheck.StatActivity}: android.view.InflateException: Binary XML file line #21: Error inflating class <unknown>
D/UNHANDLED_EXCEPTION( 5053): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
D/UNHANDLED_EXCEPTION( 5053): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621)
D/UNHANDLED_EXCEPTION( 5053): at android.app.ActivityThread.access$2200(ActivityThread.java:126)
D/UNHANDLED_EXCEPTION( 5053): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
D/UNHANDLED_EXCEPTION( 5053): at android.os.Handler.dispatchMessage(Handler.java:99)
D/UNHANDLED_EXCEPTION( 5053): at android.os.Looper.loop(Looper.java:123)
D/UNHANDLED_EXCEPTION( 5053): at android.app.ActivityThread.main(ActivityThread.java:4595)
D/UNHANDLED_EXCEPTION( 5053): at java.lang.reflect.Method.invokeNative(Native Method)
D/UNHANDLED_EXCEPTION( 5053): at java.lang.reflect.Method.invoke(Method.java:521)
D/UNHANDLED_EXCEPTION( 5053): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
D/UNHANDLED_EXCEPTION( 5053): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
D/UNHANDLED_EXCEPTION( 5053): at dalvik.system.NativeStart.main(Native Method)
D/UNHANDLED_EXCEPTION( 5053): Caused by: android.view.InflateException: Binary XML file line #21: Error inflating class <unknown>
D/UNHANDLED_EXCEPTION( 5053): at android.view.LayoutInflater.createView(LayoutInflater.java:513)
D/UNHANDLED_EXCEPTION( 5053): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
D/UNHANDLED_EXCEPTION( 5053): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
D/UNHANDLED_EXCEPTION( 5053): at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
D/UNHANDLED_EXCEPTION( 5053): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
D/UNHANDLED_EXCEPTION( 5053): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
D/UNHANDLED_EXCEPTION( 5053): at android.widget.Toast.makeText(Toast.java:235)
D/UNHANDLED_EXCEPTION( 5053): at com.eventkontor.networkcheck.StatActivity.onCreate(StatActivity.java:140)
D/UNHANDLED_EXCEPTION( 5053): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
D/UNHANDLED_EXCEPTION( 5053): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2544)
D/UNHANDLED_EXCEPTION( 5053): ... 11 more
D/UNHANDLED_EXCEPTION( 5053): Caused by: java.lang.reflect.InvocationTargetException
D/UNHANDLED_EXCEPTION( 5053): at android.widget.LinearLayout.<init>(LinearLayout.java:92)
D/UNHANDLED_EXCEPTION( 5053): at java.lang.reflect.Constructor.constructNative(Native Method)
D/UNHANDLED_EXCEPTION( 5053): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
D/UNHANDLED_EXCEPTION( 5053): at android.view.LayoutInflater.createView(LayoutInflater.java:500)
D/UNHANDLED_EXCEPTION( 5053): ... 20 more
D/UNHANDLED_EXCEPTION( 5053): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
D/UNHANDLED_EXCEPTION( 5053): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
D/UNHANDLED_EXCEPTION( 5053): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:464)
D/UNHANDLED_EXCEPTION( 5053): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:340)
D/UNHANDLED_EXCEPTION( 5053): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
D/UNHANDLED_EXCEPTION( 5053): at android.content.res.Resources.loadDrawable(Resources.java:1705)
D/UNHANDLED_EXCEPTION( 5053): at android.content.res.TypedArray.getDrawable(TypedArray.java:548)
D/UNHANDLED_EXCEPTION( 5053): at android.view.View.<init>(View.java:1850)
D/UNHANDLED_EXCEPTION( 5053): at android.view.View.<init>(View.java:1799)
D/UNHANDLED_EXCEPTION( 5053): at android.view.ViewGroup.<init>(ViewGroup.java:296)
D/UNHANDLED_EXCEPTION( 5053): ... 24 more
Thanks
Andreas