removed reference counter in widgets, fixed memory leak
This commit is contained in:
parent
4b443059ec
commit
6c0c217562
@ -28,9 +28,6 @@ namespace cv
|
|||||||
class Impl;
|
class Impl;
|
||||||
Impl *impl_;
|
Impl *impl_;
|
||||||
friend struct WidgetAccessor;
|
friend struct WidgetAccessor;
|
||||||
|
|
||||||
void create();
|
|
||||||
void release();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -7,47 +7,27 @@ class cv::viz::Widget::Impl
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
vtkSmartPointer<vtkProp> prop;
|
vtkSmartPointer<vtkProp> prop;
|
||||||
int ref_counter;
|
|
||||||
|
|
||||||
Impl() : prop(0) {}
|
Impl() : prop(0) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
cv::viz::Widget::Widget() : impl_(0)
|
cv::viz::Widget::Widget() : impl_( new Impl() ) { }
|
||||||
{
|
|
||||||
create();
|
|
||||||
}
|
|
||||||
|
|
||||||
cv::viz::Widget::Widget(const Widget& other) : impl_(other.impl_)
|
cv::viz::Widget::Widget(const Widget& other) : impl_( new Impl() )
|
||||||
{
|
{
|
||||||
if (impl_) CV_XADD(&impl_->ref_counter, 1);
|
if (other.impl_ && other.impl_->prop) impl_->prop = other.impl_->prop;
|
||||||
}
|
}
|
||||||
|
|
||||||
cv::viz::Widget& cv::viz::Widget::operator=(const Widget& other)
|
cv::viz::Widget& cv::viz::Widget::operator=(const Widget& other)
|
||||||
{
|
{
|
||||||
if (this != &other)
|
if (!impl_) impl_ = new Impl();
|
||||||
{
|
if (other.impl_) impl_->prop = other.impl_->prop;
|
||||||
release();
|
|
||||||
impl_ = other.impl_;
|
|
||||||
if (impl_) CV_XADD(&impl_->ref_counter, 1);
|
|
||||||
}
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
cv::viz::Widget::~Widget()
|
cv::viz::Widget::~Widget()
|
||||||
{
|
{
|
||||||
release();
|
if (impl_)
|
||||||
}
|
|
||||||
|
|
||||||
void cv::viz::Widget::create()
|
|
||||||
{
|
|
||||||
if (impl_) release();
|
|
||||||
impl_ = new Impl();
|
|
||||||
impl_->ref_counter = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void cv::viz::Widget::release()
|
|
||||||
{
|
|
||||||
if (impl_ && CV_XADD(&impl_->ref_counter, -1) == 1)
|
|
||||||
{
|
{
|
||||||
delete impl_;
|
delete impl_;
|
||||||
impl_ = 0;
|
impl_ = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user