What is link counting? In particular, what is it for C ++?
In simple words, reference counting means counting references to an object.
C ++ typically uses the RAII technique. In this case, the ability to control the release of an object of type is tied to the type of object itself. This means that the user does not need to explicitly control the lifetime of the object and its release explicitly. The functionality for this control is built into the object itself.
This function means that the object must exist and remain valid as long as there are interested parties that reference the object, and this is achieved by counting the links. Each time an object is divided (copied), the reference counter (usually a member within the class type) increases and each time the destructor is called a counter, decreases when the counter reaches 0, the object is not referenced by anyone, and it marks the end of it life and therefore collapses.
What are the problems we may encounter if we do not handle them?
This would mean no more than RAII, but endless and often erroneous resource management manually.
In short, programming nightmares.
Does all languages require reference counting?
Languages do not require reference counting, but using this method provides very simple use and less effort for language users. Therefore, most languages prefer to use it to provide these benefits to their users.
Alok save
source share