3 ms·
The purpose of the reference count is to only deallocate memory once. You create it (copy constructor, count = 1), you pass it to a function (count = 2), come o
by zandorg 18y ago
The purpose of the reference count is to only deallocate memory once. You create it (copy constructor, count = 1), you pass it to a function (count = 2), come out of the function (destructor, count = 1) and finally return from the original function (count = 0, deallocate). It's like passing a hashtable around in Lisp - it doesn't pass a copy, it passes a pointer, and thus is more efficient on memory usage and speed.