View Issue Details

IDProjectCategoryView StatusLast Update
0025321LazarusLCLpublic2013-11-18 16:42
ReporteraccSoneAssigned ToPaul Ishenin 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformdarwin x86_64OSOSXOS Version10.6.8
Product Version1.3 (SVN)Product Build 
Target VersionFixed in Version1.2.0 
Summary0025321: Several __NSAutoreleaseNoPool console messages just on CocoaGDIObjects initialization
DescriptionDuring initialization of CocoaGDIObjects the following console messages appear:
16.11.13 12:40:15 project1[2022] *** __NSAutoreleaseNoPool(): Object 0x100a1d620 of class NSCFNumber autoreleased with no pool in place - just leaking
16.11.13 12:40:15 project1[2022] *** __NSAutoreleaseNoPool(): Object 0x100a1e000 of class NSCFNumber autoreleased with no pool in place - just leaking
16.11.13 12:40:15 project1[2022] *** __NSAutoreleaseNoPool(): Object 0x100a1e020 of class NSCFNumber autoreleased with no pool in place - just leaking
16.11.13 12:40:15 project1[2022] *** __NSAutoreleaseNoPool(): Object 0x100a05040 of class NSCFDictionary autoreleased with no pool in place - just leaking
16.11.13 12:40:15 project1[2022] *** __NSAutoreleaseNoPool(): Object 0x7fff70ebc470 of class NSCFString autoreleased with no pool in place - just leaking
16.11.13 12:40:15 project1[2022] *** __NSAutoreleaseNoPool(): Object 0x7fff70ebafd0 of class NSCFString autoreleased with no pool in place - just leaking
16.11.13 12:40:15 project1[2022] *** __NSAutoreleaseNoPool(): Object 0x7fff70eb9210 of class NSCFString autoreleased with no pool in place - just leaking
16.11.13 12:40:15 project1[2022] *** __NSAutoreleaseNoPool(): Object 0x7fff70ebca70 of class NSCFString autoreleased with no pool in place - just leaking
16.11.13 12:40:15 project1[2022] *** __NSAutoreleaseNoPool(): Object 0x7fff70eb9a90 of class NSCFString autoreleased with no pool in place - just leaking
16.11.13 12:40:15 project1[2022] *** __NSAutoreleaseNoPool(): Object 0x7fff70eb5b50 of class NSCFString autoreleased with no pool in place - just leaking
16.11.13 12:40:15 project1[2022] *** __NSAutoreleaseNoPool(): Object 0x7fff710185a8 of class NSCFString autoreleased with no pool in place - just leaking
16.11.13 12:40:15 project1[2022] *** __NSAutoreleaseNoPool(): Object 0x7fff70eb5b50 of class NSCFString autoreleased with no pool in place - just leaking
16.11.13 12:40:15 project1[2022] *** __NSAutoreleaseNoPool(): Object 0x7fff70eb9a90 of class NSCFString autoreleased with no pool in place - just leaking
16.11.13 12:40:15 project1[2022] *** __NSAutoreleaseNoPool(): Object 0x7fff710185a8 of class NSCFString autoreleased with no pool in place - just leaking
16.11.13 12:40:15 project1[2022] *** __NSAutoreleaseNoPool(): Object 0x7fff70eb9a90 of class NSCFString autoreleased with no pool in place - just leaking
16.11.13 12:40:15 project1[2022] *** __NSAutoreleaseNoPool(): Object 0x7fff710185a8 of class NSCFString autoreleased with no pool in place - just leaking
16.11.13 12:40:15 project1[2022] *** __NSAutoreleaseNoPool(): Object 0x7fff70eb9a90 of class NSCFString autoreleased with no pool in place - just leaking
16.11.13 12:40:15 project1[2022] *** __NSAutoreleaseNoPool(): Object 0x7fff70eb9a90 of class NSCFString autoreleased with no pool in place - just leaking
16.11.13 12:40:15 project1[2022] *** __NSAutoreleaseNoPool(): Object 0x7fff70eb9a90 of class NSCFString autoreleased with no pool in place - just leaking
16.11.13 12:40:15 project1[2022] *** __NSAutoreleaseNoPool(): Object 0x100a15220 of class NSCFNumber autoreleased with no pool in place - just leaking
16.11.13 12:40:15 project1[2022] *** __NSAutoreleaseNoPool(): Object 0x100a24ed0 of class __NSFontTypefaceInfo autoreleased with no pool in place - just leaking
16.11.13 12:40:15 project1[2022] *** __NSAutoreleaseNoPool(): Object 0x100a25410 of class NSAffineTransform autoreleased with no pool in place - just leaking
16.11.13 12:40:15 project1[2022] *** __NSAutoreleaseNoPool(): Object 0x100a25890 of class NSFont autoreleased with no pool in place - just leaking
16.11.13 12:40:15 project1[2022] *** __NSAutoreleaseNoPool(): Object 0x100a25ac0 of class NSFont autoreleased with no pool in place - just leaking
16.11.13 12:40:15 project1[2022] *** __NSAutoreleaseNoPool(): Object 0x100a2b120 of class __NSArray0 autoreleased with no pool in place - just leaking
16.11.13 12:40:15 project1[2022] *** __NSAutoreleaseNoPool(): Object 0x100a278e0 of class NSCustomReleaseData autoreleased with no pool in place - just leaking

That will lead to memory leaks.
Steps To ReproduceCreate simpe 64bit cocoa app, run it and you will see the messages in console during CocoaGDIObjects initalization section.

initialization
  DefaultBrush := TCocoaBrush.CreateDefault;
  DefaultPen := TCocoaPen.CreateDefault;
  DefaultFont := TCocoaFont.CreateDefault;
  DefaultBitmap := TCocoaBitmap.CreateDefault;
  DefaultContext := TCocoaBitmapContext.Create;
  DefaultContext.Bitmap := DefaultBitmap;

They are created during DefaultFont and DefaultBitmap creation.
Additional InformationSolution:

constructor TCocoaFont.CreateDefault(AGlobal: Boolean = False);
begin
  Create(NSFont.systemFontOfSize(0));
end;

has no NSAutoreleasePool coverage. NSAutoreleasePool handling has to be reworked for TCocoaFont
TagsNo tags attached.
Fixed in Revision43457
LazTarget-
Widgetset
Attached Files
  • fix_0025321.diff (2,672 bytes)
    Index: /Developer/lazarus_trunc/lcl/interfaces/cocoa/cocoaobject.inc
    ===================================================================
    --- /Developer/lazarus_trunc/lcl/interfaces/cocoa/cocoaobject.inc	(revision 43444)
    +++ /Developer/lazarus_trunc/lcl/interfaces/cocoa/cocoaobject.inc	(working copy)
    @@ -90,12 +90,23 @@
       {  Creates the AutoreleasePool }
       pool := NSAutoreleasePool.alloc.init;
     
    +
       NSMessageWnd := NSStringUTF8('HWND');
       NSMessageMsg := NSStringUTF8('MSG');
       NSMessageWParam := NSStringUTF8('WPARAM');
       NSMessageLParam := NSStringUTF8('LPARAM');
       NSMessageResult := NSStringUTF8('RESULT');
     
    +
    +   DefaultBrush := TCocoaBrush.CreateDefault;
    +  DefaultPen := TCocoaPen.CreateDefault;
    +  DefaultFont := TCocoaFont.CreateDefault;
    +  DefaultBitmap := TCocoaBitmap.CreateDefault;
    +  DefaultContext := TCocoaBitmapContext.Create;
    +  DefaultContext.Bitmap := DefaultBitmap;
    +
    +  ScreenContext := TCocoaContext.Create(DefaultContext.ctx);
    +
       InitStockItems;
     end;
     
    @@ -108,13 +119,23 @@
     begin
       inherited Destroy;
     
    +     ScreenContext.Free;
    +  DefaultContext.Free;
    +
    +  DefaultBrush.Free;
    +  DefaultPen.Free;
    +  DefaultFont.Free;
    +  DefaultBitmap.Free;
    +
       FreeSysColorBrushes;
       FreeStockItems;
     
       CocoaWidgetSet := nil;
     
       {  Releases the AutoreleasePool }
    -  pool.release;
    +   pool.drain;
    +
    +
     end;
     
     {------------------------------------------------------------------------------
    
    Index: /Developer/lazarus_trunc/lcl/interfaces/cocoa/cocoagdiobjects.pas
    ===================================================================
    --- /Developer/lazarus_trunc/lcl/interfaces/cocoa/cocoagdiobjects.pas	(revision 43444)
    +++ /Developer/lazarus_trunc/lcl/interfaces/cocoa/cocoagdiobjects.pas	(working copy)
    @@ -1121,6 +1121,7 @@
     end;
     
     procedure TCocoaBitmapContext.SetBitmap(const AValue: TCocoaBitmap);
    +
     begin
       if Assigned(ctx) then
       begin
    @@ -1132,6 +1133,7 @@
       begin
         FBitmap := AValue;
         ctx := NSGraphicsContext.graphicsContextWithBitmapImageRep(Bitmap.ImageRep);
    +    ctx.retain; // extend live beyond NSAutoreleasePool
         InitDraw(Bitmap.Width, Bitmap.Height);
       end;
     end;
    @@ -2624,22 +2626,9 @@
     end;
     
     initialization
    -  DefaultBrush := TCocoaBrush.CreateDefault;
    -  DefaultPen := TCocoaPen.CreateDefault;
    -  DefaultFont := TCocoaFont.CreateDefault;
    -  DefaultBitmap := TCocoaBitmap.CreateDefault;
    -  DefaultContext := TCocoaBitmapContext.Create;
    -  DefaultContext.Bitmap := DefaultBitmap;
     
    -  ScreenContext := TCocoaContext.Create(DefaultContext.ctx);
     
     finalization
    -  ScreenContext.Free;
    -  DefaultContext.Free;
     
    -  DefaultBrush.Free;
    -  DefaultPen.Free;
    -  DefaultFont.Free;
    -  DefaultBitmap.Free;
     
     end.
    
    
    fix_0025321.diff (2,672 bytes)

Activities

accSone

2013-11-16 16:44

developer   ~0071337

Initializations in cocoaobjectt.inc where not included by widgetset nsautoreleasepool. Moved them (see fix).

accSone

2013-11-16 16:44

developer  

fix_0025321.diff (2,672 bytes)
Index: /Developer/lazarus_trunc/lcl/interfaces/cocoa/cocoaobject.inc
===================================================================
--- /Developer/lazarus_trunc/lcl/interfaces/cocoa/cocoaobject.inc	(revision 43444)
+++ /Developer/lazarus_trunc/lcl/interfaces/cocoa/cocoaobject.inc	(working copy)
@@ -90,12 +90,23 @@
   {  Creates the AutoreleasePool }
   pool := NSAutoreleasePool.alloc.init;
 
+
   NSMessageWnd := NSStringUTF8('HWND');
   NSMessageMsg := NSStringUTF8('MSG');
   NSMessageWParam := NSStringUTF8('WPARAM');
   NSMessageLParam := NSStringUTF8('LPARAM');
   NSMessageResult := NSStringUTF8('RESULT');
 
+
+   DefaultBrush := TCocoaBrush.CreateDefault;
+  DefaultPen := TCocoaPen.CreateDefault;
+  DefaultFont := TCocoaFont.CreateDefault;
+  DefaultBitmap := TCocoaBitmap.CreateDefault;
+  DefaultContext := TCocoaBitmapContext.Create;
+  DefaultContext.Bitmap := DefaultBitmap;
+
+  ScreenContext := TCocoaContext.Create(DefaultContext.ctx);
+
   InitStockItems;
 end;
 
@@ -108,13 +119,23 @@
 begin
   inherited Destroy;
 
+     ScreenContext.Free;
+  DefaultContext.Free;
+
+  DefaultBrush.Free;
+  DefaultPen.Free;
+  DefaultFont.Free;
+  DefaultBitmap.Free;
+
   FreeSysColorBrushes;
   FreeStockItems;
 
   CocoaWidgetSet := nil;
 
   {  Releases the AutoreleasePool }
-  pool.release;
+   pool.drain;
+
+
 end;
 
 {------------------------------------------------------------------------------

Index: /Developer/lazarus_trunc/lcl/interfaces/cocoa/cocoagdiobjects.pas
===================================================================
--- /Developer/lazarus_trunc/lcl/interfaces/cocoa/cocoagdiobjects.pas	(revision 43444)
+++ /Developer/lazarus_trunc/lcl/interfaces/cocoa/cocoagdiobjects.pas	(working copy)
@@ -1121,6 +1121,7 @@
 end;
 
 procedure TCocoaBitmapContext.SetBitmap(const AValue: TCocoaBitmap);
+
 begin
   if Assigned(ctx) then
   begin
@@ -1132,6 +1133,7 @@
   begin
     FBitmap := AValue;
     ctx := NSGraphicsContext.graphicsContextWithBitmapImageRep(Bitmap.ImageRep);
+    ctx.retain; // extend live beyond NSAutoreleasePool
     InitDraw(Bitmap.Width, Bitmap.Height);
   end;
 end;
@@ -2624,22 +2626,9 @@
 end;
 
 initialization
-  DefaultBrush := TCocoaBrush.CreateDefault;
-  DefaultPen := TCocoaPen.CreateDefault;
-  DefaultFont := TCocoaFont.CreateDefault;
-  DefaultBitmap := TCocoaBitmap.CreateDefault;
-  DefaultContext := TCocoaBitmapContext.Create;
-  DefaultContext.Bitmap := DefaultBitmap;
 
-  ScreenContext := TCocoaContext.Create(DefaultContext.ctx);
 
 finalization
-  ScreenContext.Free;
-  DefaultContext.Free;
 
-  DefaultBrush.Free;
-  DefaultPen.Free;
-  DefaultFont.Free;
-  DefaultBitmap.Free;
 
 end.

fix_0025321.diff (2,672 bytes)

Paul Ishenin

2013-11-18 13:03

manager   ~0071375

Last edited: 2013-11-18 13:03

View 2 revisions

Thanks, applied. I leaved 'release' instead of 'drain' since it should not have any effect for cocoa widgetset code. At least I hope so.

Please close if ok.

Issue History

Date Modified Username Field Change
2013-11-16 11:48 accSone New Issue
2013-11-16 16:44 accSone Note Added: 0071337
2013-11-16 16:44 accSone File Added: fix_0025321.diff
2013-11-17 09:41 Zeljan Rikalo Assigned To => Paul Ishenin
2013-11-17 09:41 Zeljan Rikalo Status new => assigned
2013-11-18 13:03 Paul Ishenin Fixed in Revision => 43457
2013-11-18 13:03 Paul Ishenin LazTarget => -
2013-11-18 13:03 Paul Ishenin Note Added: 0071375
2013-11-18 13:03 Paul Ishenin Status assigned => resolved
2013-11-18 13:03 Paul Ishenin Fixed in Version => 1.2.0
2013-11-18 13:03 Paul Ishenin Resolution open => fixed
2013-11-18 13:03 Paul Ishenin Note Edited: 0071375 View Revisions
2013-11-18 16:42 accSone Status resolved => closed