Skip to content

Commit

Permalink
Revert "fix: 修改内存泄露问题"
Browse files Browse the repository at this point in the history
This reverts commit 7efd5d2.
  • Loading branch information
xzl01 committed Jul 18, 2023
1 parent b608210 commit 2fa6097
Showing 1 changed file with 6 additions and 37 deletions.
43 changes: 6 additions & 37 deletions src/widgets/danchors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,34 +381,12 @@ class DAnchorsBasePrivate : public QSharedData
DAnchorsBasePrivate(DAnchorsBase *qq): q_ptr(qq) {}
~DAnchorsBasePrivate()
{
doDestory();
}
void tryDestory()
{
// TODO 应该是析构函数调用, 当ref.load() == 1时,提前释放资源。
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
if (ref.loadRelaxed () == 1)
#else
if (ref.load() == 1)
#endif
doDestory();
}
void doDestory()
{
#define SAFE_DELETE(pointer) \
if (pointer) { \
delete pointer; \
pointer = nullptr; \
}

SAFE_DELETE(top);
SAFE_DELETE(bottom);
SAFE_DELETE(left);
SAFE_DELETE(right);
SAFE_DELETE(horizontalCenter);
SAFE_DELETE(verticalCenter);

#undef SAFE_DELETE
delete top;
delete bottom;
delete left;
delete right;
delete horizontalCenter;
delete verticalCenter;
}

static void setWidgetAnchorsBase(const QWidget *w, DAnchorsBase *b)
Expand Down Expand Up @@ -687,15 +665,6 @@ DAnchorsBase::DAnchorsBase(QWidget *w):
DAnchorsBase::~DAnchorsBase()
{
DAnchorsBasePrivate::removeWidgetAnchorsBase(target(), this);
/** TODO dynamic_cast会报警告`QSharedData is not polymorphic`,因为没有虚函数.
因为由QExplicitlySharedDataPointer管理, QSharedData没有虚析构,
导致delete QSharedData时,不会调用子类~DAnchorsBasePrivate.
之后改成QExplicitlySharedDataPointer<DAnchorsBasePrivate> d_ptr,
d_ptr计数为0会调用~DAnchorsBasePrivate
*/
if (auto p = reinterpret_cast<DAnchorsBasePrivate*>(d_ptr.data())) {
p->tryDestory();
}
}

QWidget *DAnchorsBase::target() const
Expand Down

0 comments on commit 2fa6097

Please sign in to comment.