开发者

Memory leaks found when Local Binder has a reference to Service

开发者 https://www.devze.com 2023-03-20 21:07 出处:网络
I\'ve used non static inner class as binder to all my services.however when i run the MAT tool to check the Memory leaks i found that all my binder class not getting clear. so i found the following tw

I've used non static inner class as binder to all my services.however when i run the MAT tool to check the Memory leaks i found that all my binder class not getting clear. so i found the following two link related to this issue.

http://code.google.com/p/android/issues/detail?id=6426

following link discues a workaround for this:using weak refreshments http://www.ozdroid.com/#!BLOG/2010/12/19/How_to_make_a_开发者_如何学JAVAlocal_Service_and_bind_to_it_in_Android

  1. Since this is a known issue with the current version of the android SDK, is there a idea of when it will be fixed?

2.The solution provided above is a standered recommended approach? or is there any workaround to fix.

3 other than this what sort of memory leaks introduce when using the binder pattern.

Sam

I'm using the Android SDK 2.2.


I found a similar leak issue when you pass a callback Object through a Binder to a Service: Binder preventing garbage collection

I believe that when you bind to a service the ServiceConnection Object probably won't be collected until you unbind. Thus your ServiceConnection ideally shouldn't hold on to anything that consumes a lot of memory or something you may want garbage collected while the connection is ongoing. This means that a non-static inner class is probably not a good idea because non-static inner classes have a pointer to their parent, that means the parent will not be garbage collected until the connection is closed.

I don't think this is something that can really be fixed, it is necessary to keep the ServiceConnection Object alive as long as there is a connection, we user-engineers just need to be careful about what side-effects that may have.

0

精彩评论

暂无评论...
验证码 换一张
取 消