diff --git a/cocos/renderer/backend/metal/CommandBufferMTL.h b/cocos/renderer/backend/metal/CommandBufferMTL.h index 7f9e589de6..7e3874a721 100644 --- a/cocos/renderer/backend/metal/CommandBufferMTL.h +++ b/cocos/renderer/backend/metal/CommandBufferMTL.h @@ -195,6 +195,7 @@ private: dispatch_semaphore_t _frameBoundarySemaphore; RenderPassDescriptor _prevRenderPassDescriptor; + NSAutoreleasePool* _autoReleasePool = nil; }; // end of _metal group diff --git a/cocos/renderer/backend/metal/CommandBufferMTL.mm b/cocos/renderer/backend/metal/CommandBufferMTL.mm index 2df6d1b3fe..6081d7b969 100644 --- a/cocos/renderer/backend/metal/CommandBufferMTL.mm +++ b/cocos/renderer/backend/metal/CommandBufferMTL.mm @@ -220,6 +220,7 @@ CommandBufferMTL::~CommandBufferMTL() void CommandBufferMTL::beginFrame() { + _autoReleasePool = [[NSAutoreleasePool alloc] init]; dispatch_semaphore_wait(_frameBoundarySemaphore, DISPATCH_TIME_FOREVER); _mtlCommandBuffer = [_mtlCommandQueue commandBuffer]; @@ -366,6 +367,7 @@ void CommandBufferMTL::endFrame() [_mtlCommandBuffer commit]; [_mtlCommandBuffer release]; DeviceMTL::resetCurrentDrawable(); + [_autoReleasePool drain]; } void CommandBufferMTL::afterDraw()