diff --git a/dune/common/shared_ptr.hh b/dune/common/shared_ptr.hh index 62854abc9451946dd0b6c0cb705448ae99a91c97..64a4b927c6feeef5f0ce64d7f41f20b8bfc4b243 100644 --- a/dune/common/shared_ptr.hh +++ b/dune/common/shared_ptr.hh @@ -90,6 +90,11 @@ namespace Dune /** \brief Dereference as const pointer */ inline const element_type* operator->() const; + /** \brief Decrease the reference count by one and free the memory if the + reference count has reached 0 + */ + inline void reset(); + /** * @brief Deallocates the references object if no other * pointers reference it. @@ -183,6 +188,15 @@ namespace Dune return rep_->count_; } + template<class T> + inline void shared_ptr<T>::reset() + { + if(rep_!=0 && --(rep_->count_)==0) { + delete rep_; + rep_=0; + } + } + template<class T> inline void shared_ptr<T>::deallocate() {