BUG: intrusive pointer and weak_ptr
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello,
I think I found BUG.
Let we have this program:
- -- cut here --
#include
"Petr Ferschmann"
But in case of usage of intrusive pointer it doesn't call destructor - because there is weak pointer.
But when I undefine INTR and it uses non-intrusive it works as expected. This is only modelling case to simulate bug.
You can't call it a bug until there's documentation which tells you what you have a right to expect ;-) In this case, it's not a bug. You can implement the dispose() function on your class to throw away resources when the last shared_ptr reference goes away, but weak_ptr references still exist. -- ----------------------------------------------------------- David Abrahams * Boost Consulting dave@boost-consulting.com * http://www.boost-consulting.com
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Thank you for your answer. I know that intrusive_ptr is not documented yet. But in documentation of weak_ptr is written that when all shared_ptr are destroyed all weak_ptr are set to 0. And it of course works in that style for normal shared pointer. But when I am using weak_ptr with intrusive_ptr it know works like normal pointer? I think I missed something. Is it bug or feature? Thank yo for your answer.
You can't call it a bug until there's documentation which tells you what you have a right to expect ;-)
In this case, it's not a bug. You can implement the dispose() function on your class to throw away resources when the last shared_ptr reference goes away, but weak_ptr references still exist.
- -- Petr "Fers" Ferschmann -=[ petr@ferschmann.cz ]==[ http://petr.ferschmann.cz/ ]=- - -=[ Koukni na http://www.postcard.cz/ ]==[ +420 604/781 009 ]=- GPG Fingerprint: [83B0 6378 7A9D D993 035E 60BD FEEC F665 D2C8 1B9A] -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) iD4DBQE9mZmp/uz2ZdLIG5oRAm+OAJi1LRmqGWCZvtavAc+mhykBu+YBAJ9BjYFS 6PKKvbL7QrP/B20H9FZ/2g== =st3J -----END PGP SIGNATURE-----
From: "Petr Ferschmann"
Thank you for your answer.
I know that intrusive_ptr is not documented yet.
But in documentation of weak_ptr is written that when all shared_ptr are destroyed all weak_ptr are set to 0. And it of course works in that style for normal shared pointer.
If you test the weak_ptr, you'll see that it will properly report that it's expired(); use_count() will be zero; and if you try to construct a shared_ptr from it, the construction will fail.
But when I am using weak_ptr with intrusive_ptr it know works like normal pointer?
I think I missed something. Is it bug or feature?
It is a "feature". The reference count is contained in counted_base, and it's embedded into the object. It is not possible to destroy the object without also destroying the counted_base, and this cannot happen while there are still weak pointers to that counted_base. That's why counted_base::dispose() is invoked when the last shared_ptr is destroyed, to let you release the resources contained in your object.
participants (3)
-
David Abrahams
-
Peter Dimov
-
Petr Ferschmann