From 6d9f1686a7cf9803fb84460b0fc19dc24d5bef94 Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Fri, 13 Jul 2018 01:12:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DGC=E6=B8=85=E7=90=86=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E6=97=B6=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/Base/GC.cpp | 16 +++++++++++++--- core/e2dbase.h | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/core/Base/GC.cpp b/core/Base/GC.cpp index 2d2d0780..00cb7505 100644 --- a/core/Base/GC.cpp +++ b/core/Base/GC.cpp @@ -42,6 +42,7 @@ GC GC::_instance; e2d::GC::GC() : _notifyed(false) + , _cleanup(false) , _pool() { } @@ -91,11 +92,20 @@ void e2d::GC::flush() void e2d::GC::clear() { + _instance._cleanup = true; for (auto pair : _instance._pool) { - delete pair.first; + if (pair.second) + { + delete[] pair.first; + } + else + { + delete pair.first; + } } _instance._pool.clear(); + _instance._cleanup = false; } void e2d::GC::autorelease(Ref * ref) @@ -124,7 +134,7 @@ void e2d::GC::autoreleaseArray(Ref * ref) void e2d::GC::retain(Ref * ref) { - if (ref) + if (ref && !_instance._cleanup) { auto iter = _instance._pool.find(ref); if (iter != _instance._pool.end()) @@ -136,7 +146,7 @@ void e2d::GC::retain(Ref * ref) void e2d::GC::release(Ref * ref) { - if (ref) + if (ref && !_instance._cleanup) { auto iter = _instance._pool.find(ref); if (iter != _instance._pool.end()) diff --git a/core/e2dbase.h b/core/e2dbase.h index 31a25d12..08fd34a8 100644 --- a/core/e2dbase.h +++ b/core/e2dbase.h @@ -512,6 +512,7 @@ private: private: bool _notifyed; + bool _cleanup; std::map _pool; static GC _instance;