when to use weak pointer (wp) in android native framework (AOSP) -
i know different between sp & wp, , sp automatically recollect dynamically allocated memory. not know when , how wp used? can give me example? thx~
you must know using sp increase ref count of object, while using wp won't. wp store of address, cannot used access fields of object, unless promote it. if object released, wp.promote() return null pointer.
so, wp used in scenarios want have reference cache of memory object not want hold it. access data promote wp every time, , if object not available more, need (ask other code to) create again.
Comments
Post a Comment