Reference counting in C++
I implemented reference counting in my program, and found out many
problems associated with it. I wonder if the following problems can be
solved automatically rather manually ?
1. In its member function, an object manages to destroy last
reference to itself and thus destructs before the end of the member
In attached counted body, this can be solved manually by taking a
reference to itself in the beginning of the function. Automatically?
What about in detached counted body?
2. An object is referenced during its constructor (for example in
calling other member functions). Object is destroyed before end of the
constructor function, because there can't be any references to it yet
(assuming the reference to it was not stored).
In attached counted body, this can be solved manually by creating an
object that in its constructor adds the reference count and in its
destructor subtracts the reference count, without deleting the object if
count falls to zero. Automatically? What about in detached counted body?
3. An object with static or automatic lifetime is referenced.
4. A reference counted object is used through a pointer.
These two are something that I think that can't be solved. One must just
inform the code user to not to do this.
5. Object's pointer is assigned to more than one reference.
Clearly attached counted body solution does not have this problem, but
how to solve this with detached counted body ?
6. Program contains cyclic references.
7. When reference counting is not used, the machinery is still
This is a problem with attached counted body.
|All times are GMT. The time now is 07:06 AM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.