android - Can someone explain RemoteViews GC behavior? -


i have download task reports progress notification periodically. awhile using 1 removeview private member update each time.

for example:

private remoteviews mremoteview; protected void oncreate(){     mremoteview = new remoteviews( getpackagename(), r.layout.custom_layout )     contentview.setimageviewresource(r.id.notification_icon, r.drawable.downloads);     contentview.settextviewtext(r.id.notification_text, "downloading file " + (int)( (double)progress/(double)max * 100 ) + "%");     contentview.setprogressbar(r.id.mprogress, max, progress, false);      notification.contentview = contentview;     mnotificationmanager.notify(hello_id, notification); }  protected void onprogressupdate(integer... prog) {     contentview.setprogressbar(r.id.mprogress, max, progress, false);     mnotificationmanager.notify(hello_id, notification); } 

however, found gc clearing out space , slowing app down crawl long time. tried creating new remoteviews each time updated, , works. i'm wondering why is. found link here kind of helpful, i'm looking more information.

here's code works:

protected void onprogressupdate(integer... prog) {         remoteviews contentview = new remoteviews(getpackagename(), r.layout.custom_notification_layout);         contentview.setimageviewresource(r.id.notification_icon, r.drawable.downloads);         contentview.settextviewtext(r.id.notification_text, "downloading file " + (int)( (double)progress/(double)max * 100 ) + "%");         contentview.setprogressbar(r.id.mprogress, max, progress, false);          notification.contentview = contentview;         mnotificationmanager.notify(hello_id, notification);     } 

the link provided explains it:

remoteviews used creating view in remote process. it's not view, set of commands queued. queue serialized, sent remote process, deserialized , set of actions executed. result build view in remote process.

as link explains it: every time call method on remoteviews, actions added it's queue. unfortunately there no way clear queue, keeps on growing, until oom exception.

now, queue internally backed array (as collections). when queue fills it's internal array needs create new bigger 1 , copy old data. gc clears old array. since remoteviews internal queue growing, new arrays created , gc clearing old arrays.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -