mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-08 04:58:11 +02:00
Cocoa: MainPool is divided into two stages, covering the whole cycle, fix resources leak
This commit is contained in:
parent
7f00662152
commit
b65ca17223
@ -299,6 +299,22 @@ const
|
||||
// Lack of documentation, provisional definition
|
||||
LazarusApplicationDefinedSubtypeWakeup = 13579;
|
||||
|
||||
procedure InternalInit;
|
||||
begin
|
||||
// MacOSX 10.6 reports a lot of warnings during initialization process
|
||||
// adding the autorelease pool for the whole Cocoa widgetset
|
||||
MainPool := NSAutoreleasePool.alloc.init;
|
||||
end;
|
||||
|
||||
procedure InternalFinal;
|
||||
begin
|
||||
if Assigned(MainPool) then
|
||||
begin
|
||||
MainPool.release;
|
||||
MainPool := nil;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure wakeupEventLoop;
|
||||
var
|
||||
ev: NSevent;
|
||||
@ -479,6 +495,8 @@ end;
|
||||
{$ifdef COCOALOOPOVERRIDE}
|
||||
procedure TCocoaApplication.run;
|
||||
begin
|
||||
InternalFinal; // MainPool Stage 1 final
|
||||
InternalInit; // MainPool Stage 2 init
|
||||
{$ifdef COCOAPPRUNNING_SETINTPROPERTY}
|
||||
setValue_forKey(NSNumber.numberWithBool(true), NSSTR('_running'));
|
||||
{$endif}
|
||||
@ -746,22 +764,6 @@ begin
|
||||
end;
|
||||
{$endif}
|
||||
|
||||
procedure InternalInit;
|
||||
begin
|
||||
// MacOSX 10.6 reports a lot of warnings during initialization process
|
||||
// adding the autorelease pool for the whole Cocoa widgetset
|
||||
MainPool := NSAutoreleasePool.alloc.init;
|
||||
end;
|
||||
|
||||
procedure InternalFinal;
|
||||
begin
|
||||
if Assigned(MainPool) then
|
||||
begin
|
||||
MainPool.release;
|
||||
MainPool := nil;
|
||||
end;
|
||||
end;
|
||||
|
||||
type
|
||||
AppClassMethod = objccategory external (NSObject)
|
||||
function sharedApplication: NSApplication; message 'sharedApplication';
|
||||
@ -942,9 +944,10 @@ begin
|
||||
end;
|
||||
|
||||
initialization
|
||||
InternalInit; // MainPool Stage 1 init
|
||||
// {$I Cocoaimages.lrs}
|
||||
|
||||
finalization
|
||||
InternalFinal;
|
||||
InternalFinal; // MainPool Stage 2 Final
|
||||
|
||||
end.
|
||||
|
@ -31,8 +31,6 @@ begin
|
||||
{$IFDEF VerboseObject}
|
||||
DebugLn('TCocoaWidgetSet.AppInit');
|
||||
{$ENDIF}
|
||||
InternalInit;
|
||||
|
||||
WakeMainThread := @OnWakeMainThread;
|
||||
ScreenInfo.PixelsPerInchX := CocoaBasePPI;
|
||||
ScreenInfo.PixelsPerInchY := CocoaBasePPI;
|
||||
|
Loading…
Reference in New Issue
Block a user