In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
In this article, the editor introduces in detail "how to use android smart pointer", the content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to use android smart pointer" can help you solve your doubts.
The main points are:
1. The principle of the intelligent pointer reference counting framework: when the parent object wants to reference the child object, it uses the strong reference counting technique for the child object, and when the child object wants to reference the parent object, it uses the weak reference counting technique for the parent object. When the garbage collection system performs object collection, it can recycle the object as long as the strong reference count of the object is found to be 0, regardless of whether its weak reference count is 0 or not. If we only hold a weak reference count on an object, when we want to use this object, we don't use it directly, we have to upgrade the weak reference to a strong reference before we can use this object. In the process of transformation, if the object no longer exists, then the conversion fails, which means that the object has been destroyed and can no longer be used.
2. Smart pointer implementation framework: an object provides the reference counter, but this object does not maintain the value of the reference counter, but by the smart pointer. Specifically, the first is to define a public class responsible for providing the reference counter, and the second is to implement the corresponding smart pointer object class.
3. Android source code involves RefBase,sp,wp
(1) strong reference and weak reference count
There is an implicit object in RefBase that has a strong or weak reference count inside it.
After sp, the strong and weak reference counts are increased by 1, and the strong and weak reference counts are reduced by 1 after destructing.
After wp, the weak reference count is subtracted by 1 after the weak reference count is destructed by 1.
Strong reference is 0, causing the actual object to be delete
A weak reference of 0 will cause the implied object to be delete
(2) weak reference operation
The most important feature of the weak pointer is that it can not directly manipulate the target object, in that the weak pointer class does not overload * and-> operation symbols, while the strong pointer overloads these two operation symbols. However, if we want to manipulate the target object, we need to upgrade the weak pointer to the strong pointer.
(3) Life cycle control of target object
In addition to the strong and weak reference count, the target object life cycle control also has the flag flag.
a. If the flag bit of the object is set to 0, then as long as the strong reference count of the object is found to be 0, it will automatically delete the object.
b. If the flag bit of an object is set to OBJECT_LIFETIME_WEAK, the object will be automatically delete only if its strong reference count and weak reference count are both 0
c. If the flag bit of the object is set to OBJECT_LIFETIME_FOREVER, then the object will never be automatically delete, and the object that comes out of the new will be delete.
Read here, this article "how to use android smart pointer" article has been introduced, want to master the knowledge of this article also need to practice and use to understand, if you want to know more about the article, welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.