Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Why does it take so long to start new activity?
    primarykey
    data
    text
    <p>I have an Android activity <code>BrowseActivity</code> which load about 3000 records (@ about 100 bytes) from database into memory and show them in a <code>ListView</code>. It takes about 3 to 6 seconds in AVD to load, which is fine. </p> <p>The problem arises when I want to start a new activity from within this <code>BrowseActivity</code>. It takes about 30 seconds, even just to open the most trivial activity. Dalvik VM seems to do a LOT of garbage collecting for unknown reason. Please check <code>logcat</code> output below.</p> <pre><code>01-30 02:06:27.025: D/dalvikvm(553): GC_FOR_MALLOC freed 3889 objects / 221200 bytes in 45ms 01-30 02:06:28.234: D/dalvikvm(553): GC_FOR_MALLOC freed 2784 objects / 76864 bytes in 48ms 01-30 02:06:29.614: D/dalvikvm(553): GC_FOR_MALLOC freed 2665 objects / 70088 bytes in 64ms 01-30 02:06:30.915: D/BrowseActivity(553): Low memory status: false 01-30 02:06:30.915: D/BrowseActivity(553): Low memory threshold (KB): 16384 01-30 02:06:30.915: D/BrowseActivity(553): Memory available (KB): 451348 01-30 02:06:31.095: D/dalvikvm(553): GC_EXTERNAL_ALLOC freed 2711 objects / 85904 bytes in 62ms 01-30 02:06:49.705: D/dalvikvm(553): GC_FOR_MALLOC freed 8894 objects / 600272 bytes in 89ms 01-30 02:06:50.414: D/dalvikvm(553): GC_FOR_MALLOC freed 10757 objects / 730720 bytes in 68ms 01-30 02:06:51.105: D/dalvikvm(553): GC_FOR_MALLOC freed 10251 objects / 694864 bytes in 67ms ... and about 30 more garbage collection messages </code></pre> <p>I already experimented with lower number of records: 1 and 300. It results in a much fewer garbage collection messages (1 and 7, respectively) and a much faster activity load (1 and 6 seconds, respectively), but the memory availability difference is quite trivial:</p> <pre><code>01-30 02:03:35.295: D/BrowseActivity(491): Low memory status: false 01-30 02:03:35.295: D/BrowseActivity(491): Low memory threshold (KB): 16384 01-30 02:03:35.295: D/BrowseActivity(491): Memory available (KB): 453184 01-30 02:04:53.494: D/BrowseActivity(522): Low memory status: false 01-30 02:04:53.494: D/BrowseActivity(522): Low memory threshold (KB): 16384 01-30 02:04:53.494: D/BrowseActivity(522): Memory available (KB): 453152 </code></pre> <p>It seems that the slow activity load time is caused by GC overheads. My question is: Why does Dalvik VM does a lot of GC? Even with 3000 records, I believe it would only take top 500 KB in memory. If it's not about GC overheads, what's the other possible causes for this slow activity load?</p> <p>For the record, I logged the memory availability using the information provided by built-in class <a href="http://developer.android.com/reference/android/app/ActivityManager.MemoryInfo.html" rel="nofollow">ActivityManager.MemoryInfo</a>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload