@@ -43,7 +43,7 @@ namespace Diligent
4343{
4444
4545// This class controls the lifetime of a refcounted object
46- class RefCountersImpl final : public IReferenceCounters
46+ class RefCountersImpl : public IReferenceCounters
4747{
4848public:
4949 inline virtual ReferenceCounterValueType AddStrongRef () override final
@@ -215,14 +215,15 @@ class RefCountersImpl final : public IReferenceCounters
215215 return m_NumWeakReferences.load ();
216216 }
217217
218- private :
218+ protected :
219219 template <typename AllocatorType, typename ObjectType>
220220 friend class MakeNewRCObj ;
221221
222222 RefCountersImpl () noexcept
223223 {
224224 }
225225
226+ private:
226227 class ObjectWrapperBase
227228 {
228229 public:
@@ -448,17 +449,16 @@ class RefCountersImpl final : public IReferenceCounters
448449 }
449450 }
450451
451- void SelfDestroy ()
452- {
453- delete this ;
454- }
452+ protected:
453+ virtual void SelfDestroy () = 0;
455454
456455 ~RefCountersImpl ()
457456 {
458457 VERIFY (m_NumStrongReferences.load () == 0 && m_NumWeakReferences.load () == 0 ,
459458 " There exist outstanding references to the object being destroyed" );
460459 }
461460
461+ private:
462462 // No copies/moves
463463 // clang-format off
464464 RefCountersImpl (const RefCountersImpl&) = delete ;
@@ -492,6 +492,21 @@ class RefCountersImpl final : public IReferenceCounters
492492 std::atomic<ObjectState> m_ObjectState{ObjectState::NotInitialized};
493493};
494494
495+ class RefCountersAllocationImpl : public RefCountersImpl
496+ {
497+ private:
498+ template <typename AllocatorType, typename ObjectType>
499+ friend class MakeNewRCObj ;
500+
501+ RefCountersAllocationImpl () noexcept
502+ {
503+ }
504+
505+ void SelfDestroy () override
506+ {
507+ delete this ;
508+ }
509+ };
495510
496511// / Base class for all reference counting objects
497512template <typename Base>
@@ -654,7 +669,7 @@ class MakeNewRCObj
654669 {
655670 // Constructor of RefCountersImpl class is private and only accessible
656671 // by methods of MakeNewRCObj
657- pNewRefCounters = new RefCountersImpl {};
672+ pNewRefCounters = new RefCountersAllocationImpl {};
658673 pRefCounters = pNewRefCounters;
659674 }
660675 ObjectType* pObj = nullptr ;
0 commit comments