472,145 Members | 1,382 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

Reference counting in C++

Hello

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
function.

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
present.

This is a problem with attached counted body.

Jul 23 '05 #1
0 1658

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Elbert Lev | last post: by
1 post views Thread by ash | last post: by
1 post views Thread by Tony Johansson | last post: by
1 post views Thread by Tony Johansson | last post: by
4 posts views Thread by aaronfude | last post: by
1 post views Thread by oec.deepak | last post: by
275 posts views Thread by Astley Le Jasper | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.