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;