If the reference count used by s1 is 1, then it will destroy the line with it when it died. Consider the following:
String s2; { String s1("More Effective C++"); s2 = s1; }
At point A, s1 dies. If its refcount is 1, it will clear the storage that it shares with s2 , and s2 will use invalid storage.
The reference count is not associated with each object. As you can see from the example I gave, this would be useless, because the reference counter would never be trustworthy as an indicator that can be safely cleared.
The reference counter is associated with pieces of storage for these objects. For both s1 and s2 there is only one reference counter. They have part of the repository with "More Effective C ++". This means that there are two links to this part of the repository. Each of the two should know that there are two of them, so that they do not clear the memory that the other uses.
source share