Because many places in Android code is written in C + +, in order to ensure that pointers in C + + can be properly released, so Android introduced in fact in C + + already have smart pointer technology;
The essence of smart pointer technology is to record the number of times an object is referenced, and once the number of times detected is 0, the memory freed up by this object is self-determined.
Simple smart pointer technology because it does not solve the problem of object Circular reference: a refers to b;b reference A, such that the use of simple smart pointer technology can not be solved, so the introduction of strong pointers and weak pointers;
In fact, the strength and weakness of the pointer can be regarded as a point in the C language to the object's address (for ease of understanding), but the difference is that the strong pointer can manipulate the object, weak pointer is not enough to manipulate the object . But to know that the smart pointer is not a real pointer,
They are all an object;
The specific implementation details of Android, Luo Shenyang's blog is very clear, you can find yourself to see.
Let's just say a general feeling:
The Refbase and Lightrefbase classes are just a counter class; The real realization is sp<t> and wp<t>, and the individual feels completely indifferent to the principle, as long as it can be used.
Recently I think of why I understand the computer system in depth, the book will be the C language elements in the machine-level analysis, and now I know, when you meet the advanced language, in order to facilitate
Understanding the intricacies of the relationship, understanding it at the machine language level may be better understood and deeper, no wonder in-depth understanding of the importance of the C + + object model, which is actually about C + +
At the bottom of the implementation way, so that more clearly understand the concept of C + +, it is no wonder some people will see the C + + executable assembly implementation of the same truth.
At the same time also understand the profound significance of the understanding of a problem, while reminding oneself need to summarize and connect more to their knowledge before understanding, only the knowledge can be linked to remember the prison also can be used in the
Time to think about it quickly.
Strong pointers and weak pointers in Android