class RefCountedPart: public RefCounted 
{
public:
    RefCountedPart(RefCounted const* pParent): m_pParent(pParent) {};
    RefCountedPart(RefCountedPart const& another): m_pParent(NULL) {};
    RefCountedPart& operator=(RefCountedPart const& another) {
        return *this;
    };
protected:
    void DetachFromParent() const {
        RefCounted const* pParent = m_pParent;
        m_pParent = NULL;
    
        if (0 < GetReferenceCount()) {
            pParent->Release();
        } else {
            delete this;
        }        
    }
private:
    mutable RefCounted const* m_pParent;
    virtual void AddRef() const {
        if (m_pParent && 0 == GetReferenceCount()) {
            m_pParent->AddRef();
        }
        RefCounted::AddRef();        
    }
    virtual void Release() const {
        if (m_pParent) {
            RefCounted::DecRef();
            if (0 == GetReferenceCount()) {
                m_pParent->Release();
            }
        } else {
            RefCounted::Release();
        }        
    }        
};