From 3ce92f408f22028d2f70169e2604fc2d8e82704e Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Tue, 12 Jun 2012 15:36:33 +0000 Subject: Fixed STR#2848: Mac OS: close putative memory leak when detaching child threads. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9588 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_cocoa.mm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index fcbdb2f04..0a18c5496 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -326,8 +326,6 @@ void DataReady::HandleData(fd_set& r, fd_set& w, fd_set& x) void* DataReady::DataReadyThread(void *o) { DataReady *self = (DataReady*)o; - NSAutoreleasePool *localPool; - localPool = [[NSAutoreleasePool alloc] init]; while ( 1 ) { // loop until thread cancel or error // Thread safe local copies of data before each select() self->DataLock(); @@ -358,12 +356,14 @@ void* DataReady::DataReadyThread(void *o) { return(NULL); } // just exit DEBUGMSG("CHILD THREAD: DATA IS READY\n"); NSPoint pt={0,0}; + NSAutoreleasePool *localPool = [[NSAutoreleasePool alloc] init]; NSEvent *event = [NSEvent otherEventWithType:NSApplicationDefined location:pt modifierFlags:0 timestamp:0 windowNumber:0 context:NULL subtype:FLTKDataReadyEvent data1:0 data2:0]; [NSApp postEvent:event atStart:NO]; + [localPool release]; return(NULL); // done with thread } } @@ -1280,6 +1280,9 @@ void fl_open_display() { selector:@selector(anyWindowWillClose:) name:NSWindowWillCloseNotification object:nil]; + // necessary for secondary pthreads to be allowed to use cocoa, + // especially to create an NSAutoreleasePool. + [NSThread detachNewThreadSelector:nil toTarget:nil withObject:nil]; } } -- cgit v1.2.3