I can't understand the concept behind reference counting!
When and why an object is called reference counted?
Is it some kind of handler, like HWND, HDC etc?
Any info would be appreciated!
Printable View
I can't understand the concept behind reference counting!
When and why an object is called reference counted?
Is it some kind of handler, like HWND, HDC etc?
Any info would be appreciated!
You might want to search the Web concerning "reference counting". Simply put, the idea is to track the (number of) pointers that refer to (and own) an object, usually so that the object can be destroyed when the last such pointer no longer refers to it.
By way of example, often string classes contain a shared ptr to the data (actual characters) so things that just copy the object don't copy the data too. Only two conditions result in alteration or deletion of the string data: destruction of the final object referencing that data and if any of the string objects related to that data try to alter it (which results in the string being copied first, then altered so the original remains intact). The point of doing this is reducing memory consumption and at the same time speeding program execution, albeit only slightly.
Oh, i think i get the basic idea, but i'll search it a bit to learn more about it.