Android Developers › AppWidgets: Reusing RemoteViews instance leaks memory?

AppWidgets: Reusing RemoteViews instance leaks memory? 
2 posts by 2 authors in  Android Developers
  
Michael Elsdörfer
Join group to reply
More message actions
5/22/09
I'm writing a widget. Currently, I'm have a simple ImageView, and 
calling RemoteViews. setImageViewBitmap(). I'm using a service to do 
the updates. 

I thought it might be a good idea to reuse an existing RemoteViews 
instance, so I'm only querying it the first time around, and 
subsequently simply call setImageViewBitmap() with the new image. 

This works well initially, but after some time I first start getting 
"!!! FAILED BINDER TRANSACTION !!!" errors, and later, an OutOfMemory 
exception. 

Simply creating a new RemoveViews instance every time works flawlessy 
on the other hand. I'm just curios why that would be, any ideas?
Jeff Sharkey
Join group to reply
More message actions
5/27/09
Re: [android-developers] AppWidgets: Reusing RemoteViews instance leaks memory?
So internally RemoteViews is simply a set of actions that are 
"serialized" and sent to another process.  Each time you make a call 
to something like setDouble(), you're adding an additional action to 
RemoteViews' internal list. 

Because there isn't a way of clearing these actions from a RemoteViews 
object, all of your successive setImageViewBitmap() calls, along with 
their Bitmaps, remain in the internal list, and are actually 
"serialized" and applied each time your send it.  :( 

In this case it's best to just create a new RemoteViews object every time. 


- show quoted text -
-- 
Jeff Sharkey 
jsharkey@android.com 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值