Cocoa Port: Fix some memory leak issues, especially apparent when running Metal display views.

This commit is contained in:
rogerman 2022-04-22 18:23:46 -07:00
parent 57dd000496
commit 2e95dda3f5
3 changed files with 35 additions and 29 deletions

View File

@ -1587,10 +1587,13 @@ public:
- (void) runFetchLoop
{
NSAutoreleasePool *tempPool = nil;
pthread_mutex_lock(&_mutexFetchExecute);
do
{
tempPool = [[NSAutoreleasePool alloc] init];
while (_threadMessageID == MESSAGE_NONE)
{
pthread_cond_wait(&_condSignalFetch, &_mutexFetchExecute);
@ -1600,6 +1603,8 @@ public:
[self pushVideoDataToAllDisplayViews];
_threadMessageID = MESSAGE_NONE;
[tempPool release];
} while(true);
}
@ -1796,7 +1801,10 @@ CVReturn MacDisplayLinkCallback(CVDisplayLinkRef displayLink,
void *displayLinkContext)
{
MacClientSharedObject *sharedData = (MacClientSharedObject *)displayLinkContext;
NSAutoreleasePool *tempPool = [[NSAutoreleasePool alloc] init];
[sharedData flushAllDisplaysOnDisplayLink:displayLink timeStampNow:inNow timeStampOutput:inOutputTime];
[tempPool release];
return kCVReturnSuccess;
}

View File

@ -136,10 +136,13 @@
- (void) runMessageLoop
{
NSAutoreleasePool *tempPool = nil;
pthread_mutex_lock(&_mutexMessageLoop);
do
{
tempPool = [[NSAutoreleasePool alloc] init];
while (_threadMessageID == MESSAGE_NONE)
{
pthread_cond_wait(&_condSignalMessage, &_mutexMessageLoop);
@ -148,6 +151,7 @@
[self handleSignalMessageID:_threadMessageID];
_threadMessageID = MESSAGE_NONE;
[tempPool release];
} while(true);
}

View File

@ -778,33 +778,30 @@
{
const size_t listSize = cdvFlushList.size();
@autoreleasepool
id<MTLCommandBuffer> cbFlush = [commandQueue commandBufferWithUnretainedReferences];
id<MTLCommandBuffer> cbFinalize = [commandQueue commandBufferWithUnretainedReferences];
for (size_t i = 0; i < listSize; i++)
{
id<MTLCommandBuffer> cbFlush = [commandQueue commandBufferWithUnretainedReferences];
id<MTLCommandBuffer> cbFinalize = [commandQueue commandBufferWithUnretainedReferences];
ClientDisplay3DView *cdv = (ClientDisplay3DView *)cdvFlushList[i];
cdv->FlushView(cbFlush);
}
for (size_t i = 0; i < listSize; i++)
{
ClientDisplay3DView *cdv = (ClientDisplay3DView *)cdvFlushList[i];
cdv->FlushView(cbFlush);
}
for (size_t i = 0; i < listSize; i++)
{
ClientDisplay3DView *cdv = (ClientDisplay3DView *)cdvFlushList[i];
cdv->FinalizeFlush(cbFinalize, timeStampOutput->hostTime);
}
for (size_t i = 0; i < listSize; i++)
{
ClientDisplay3DView *cdv = (ClientDisplay3DView *)cdvFlushList[i];
cdv->FinalizeFlush(cbFinalize, timeStampOutput->hostTime);
}
[cbFlush enqueue];
[cbFinalize enqueue];
[cbFlush enqueue];
[cbFinalize enqueue];
[cbFlush commit];
[cbFinalize commit];
[cbFlush commit];
[cbFinalize commit];
#ifdef DEBUG
[commandQueue insertDebugCaptureBoundary];
[commandQueue insertDebugCaptureBoundary];
#endif
}
}
@end
@ -2528,10 +2525,7 @@ void MacMetalFetchObject::FetchFromBufferIndex(const u8 index)
MacClientSharedObject *sharedViewObject = (MacClientSharedObject *)this->_clientData;
this->_useDirectToCPUFilterPipeline = ([sharedViewObject numberViewsUsingDirectToCPUFiltering] > 0);
@autoreleasepool
{
[(MetalDisplayViewSharedData *)this->_clientData fetchFromBufferIndex:index];
}
[(MetalDisplayViewSharedData *)this->_clientData fetchFromBufferIndex:index];
}
void MacMetalFetchObject::_FetchNativeDisplayByID(const NDSDisplayID displayID, const u8 bufferIndex)