Author: manolo
Date: 2012-06-12 08:36:33 -0700 (Tue, 12 Jun 2012)
New Revision: 9588
Log:
Fixed STR#2848: Mac OS: close putative memory leak when detaching child threads.

Modified:
   branches/branch-1.3/src/Fl_cocoa.mm

Modified: branches/branch-1.3/src/Fl_cocoa.mm
===================================================================
--- branches/branch-1.3/src/Fl_cocoa.mm 2012-06-11 09:28:49 UTC (rev 9587)
+++ branches/branch-1.3/src/Fl_cocoa.mm 2012-06-12 15:36:33 UTC (rev 9588)
@@ -326,8 +326,6 @@
 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 @@
          { 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 @@
                                             
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];
   }
 }
 

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to