Reference counting - Wikipedia, the free encyclopedia
Reference counted strings are such that share memory. Reference counter is also shared and is an integer that is incremented when memory is acquired and decremented when released.
In short:
Code:
shared_string aa = "This is shared string"; // memory is allocated for text, reference counter is set to 1
shared_string bb = aa; // bb points to the same memory location as aa, reference counter is incremented and is 2 now
When strign is destroyed (or changed) the reference counter is decremented and if it reaches 0, memory is freed.