From 4f964ce6ada8f1585828f1320511acc9892b94fa Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Fri, 11 Jan 2002 20:20:07 +0000 Subject: [PATCH] Add FAQ: why no release() [SVN r12286] --- shared_ptr.htm | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/shared_ptr.htm b/shared_ptr.htm index 2108b43..4913f65 100644 --- a/shared_ptr.htm +++ b/shared_ptr.htm @@ -252,9 +252,23 @@ complex project that turned out to have cyclic-dependencies.

A. Because complexity limit implementors and complicate the specification without apparent benefit to shared_ptr users. For example, error-checking implementations might become non-conforming if they had to meet stringent complexity requirements.

+

Q. Why doesn't shared_ptr provide a release() function?
+A. shared_ptr cannot give away ownership unless it's unique() +because the other copy will still destroy the object.

+

Consider:

+
+
shared_ptr<int> a(new int);
+shared_ptr<int> b(a); // a.use_count() == b.use_count() == 2
+
+int * p = a.release();
+
+// Who owns p now? b will still call delete on it in its destructor.
+
+

[Provided by Peter Dimov]

Q. Why doesn't shared_ptr provide (your pet feature here)?
A. Because (your pet feature here) would mandate a reference counted (or a link-list, or ...) implementation. This is not the intent. -[Provided by Peter Dimov]
+[Provided by Peter Dimov]

+



Revised 11 January, 2002