Skip to content

Commit b3dba7b

Browse files
authored
Merge pull request #20131 from Mee-gu/checkMemoryLeak
fix memory leak on metal app
2 parents 965ea37 + e9a3390 commit b3dba7b

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

cocos/renderer/backend/metal/CommandBufferMTL.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ class CommandBufferMTL final : public CommandBuffer
195195

196196
dispatch_semaphore_t _frameBoundarySemaphore;
197197
RenderPassDescriptor _prevRenderPassDescriptor;
198+
NSAutoreleasePool* _autoReleasePool = nil;
198199
};
199200

200201
// end of _metal group

cocos/renderer/backend/metal/CommandBufferMTL.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ MTLCullMode toMTLCullMode(CullMode mode)
220220

221221
void CommandBufferMTL::beginFrame()
222222
{
223+
_autoReleasePool = [[NSAutoreleasePool alloc] init];
223224
dispatch_semaphore_wait(_frameBoundarySemaphore, DISPATCH_TIME_FOREVER);
224225

225226
_mtlCommandBuffer = [_mtlCommandQueue commandBuffer];
@@ -366,6 +367,7 @@ MTLCullMode toMTLCullMode(CullMode mode)
366367
[_mtlCommandBuffer commit];
367368
[_mtlCommandBuffer release];
368369
DeviceMTL::resetCurrentDrawable();
370+
[_autoReleasePool drain];
369371
}
370372

371373
void CommandBufferMTL::afterDraw()

0 commit comments

Comments
 (0)