rtc::scoped_refptr 相当于一智能指针;
应用方法,是 所应用的类 必须继承 public rtc::RefCountInterface;
和通常的设计方式一样;
template <class T>
class RefCountedObject : public T {
......;
virtual int AddRef() const { return AtomicOps::Increment(&ref_count_); }
virtual int Release() const {
int count = AtomicOps::Decrement(&ref_count_);
if (!count) {
delete this;
}
return count;
}
}
这里需要看一下 RefCountedObject 模板, 是 继承 相关的 类 (T)
当 Release() 的时候,会执行 delete this (因为继承 T,其实就是 T); 所以 T 析构函数执行了;
如果想要获取指针变量,可以通过 Tobj.release() 获取;
同时 rtc::scoped_ref