Patch from bug #18456: Fixes memory leaks in lcl-cocoa

git-svn-id: trunk@31954 -
This commit is contained in:
sekelsenmat 2011-08-12 06:16:02 +00:00
parent 413337fbfa
commit 6d6f8ddae2
4 changed files with 51 additions and 11 deletions

View File

@ -189,7 +189,8 @@ var
begin
if not Assigned(NSApp.dockTile) then Exit;
//todo: setBadgeLabel is for 10.5 only, should be removed
if NSApp.dockTile.respondsToSelector_(objcselector('setBadgeLabel:')) then begin
if NSApp.dockTile.respondsToSelector_(objcselector('setBadgeLabel:')) then
begin
ns := NSStringUtf8(ATitle);
NSApp.dockTile.setBadgeLabel(NSStringUtf8(ATitle));
ns.release;

View File

@ -211,6 +211,7 @@ type
TCocoaComboBox = objcclass(NSComboBox, NSComboBoxDataSourceProtocol)
callback : TCommonCallback;
list : TCocoaComboBoxList;
resultNS : NSString; //use to return values to combo
function comboBox_objectValueForItemAtIndex_(combo: TCocoaComboBox; row: NSInteger): id;
message 'comboBox:objectValueForItemAtIndex:';
function numberOfItemsInComboBox(combo: TCocoaComboBox): NSInteger;
@ -241,10 +242,12 @@ type
TCocoaListView = objcclass(NSTableView, NSTableViewDataSourceProtocol)
callback : TCommonCallback;
list : TCocoaStringList;
resultNS : NSString; //use to return values to combo
function numberOfRowsInTableView(aTableView: NSTableView): NSInteger; message 'numberOfRowsInTableView:';
function tableView_objectValueForTableColumn_row(tableView: NSTableView;
objectValueForTableColumn: NSTableColumn; row: NSInteger):id;
message 'tableView:objectValueForTableColumn:row:';
procedure dealloc; override;
end;
{ TCocoaGroupBox }
@ -654,10 +657,26 @@ begin
Result:=nil
else begin
if row>=list.count then Result:=nil
else Result:=NSStringUtf8(list[row]);
else
begin
resultNS.release; //so we can reuse it
resultNS := NSStringUtf8(list[row]);
Result:= ResultNS;
end;
end;
end;
procedure TCocoaListView.dealloc;
begin
if Assigned(list) then
begin
list.Free;
list:=nil;
end;
resultNS.release;
inherited dealloc;
end;
{ TCocoaStringList }
procedure TCocoaStringList.Changed;
@ -703,10 +722,12 @@ end;
procedure TCocoaComboBox.dealloc;
begin
if Assigned(list) then begin
if Assigned(list) then
begin
list.Free;
list:=nil;
end;
resultNS.release;
inherited dealloc;
end;

View File

@ -143,9 +143,10 @@ begin
if not Assigned(AMenuItem) or (AMenuItem.Handle=0) or not Assigned(AMenuItem.Parent) or (AMenuItem.Parent.Handle=0) then Exit;
ParObj:=NSObject(AMenuItem.Parent.Handle);
if ParObj.isKindOfClass_(NSMenuItem) then begin
if ParObj.isKindOfClass_(NSMenuItem) then
begin
item:=NSMenuItem(AMenuItem.Handle);
if not item.hasSubmenu then item.setSubmenu(TCocoaMenu.alloc.initWithTitle(NSString.alloc.init));
if not item.hasSubmenu then item.setSubmenu(TCocoaMenu.alloc.initWithTitle(NSSTR('')));
Parent:=TCocoaMenu(item.submenu);
end else if ParObj.isKindOfClass_(NSMenu) then
Parent:=TCocoaMenu(ParObj)
@ -172,7 +173,8 @@ begin
if AMenuItem.Caption='-' then
item:=NSMenuItem.separatorItem
else begin
else
begin
ns := NSStringUtf8(AMenuItem.Caption);
item:=TCocoaMenuItem.alloc.initWithTitle_action_keyEquivalent(
NSStringUtf8(AMenuItem.Caption),

View File

@ -186,12 +186,17 @@ function AllocSecureTextField(ATarget: TWinControl; const AParams: TCreateParams
implementation
function AllocButton(ATarget: TWinControl; const AParams: TCreateParams; btnBezel: NSBezelStyle; btnType: NSButtonType): NSButton;
var
cap: NSString;
begin
Result:=TCocoaButton.alloc.lclInitWithCreateParams(AParams);
if Assigned(Result) then begin
if Assigned(Result) then
begin
TCocoaButton(Result).callback:=TLCLCommonCallback.Create(Result, ATarget);
Result.initWithFrame(CreateParamsToNSRect(AParams));
Result.setTitle(NSStringUTF8(AParams.Caption));
cap := NSStringUTF8(AParams.Caption);
Result.setTitle(cap);
cap.release;
if btnBezel<>0 then Result.setBezelStyle(btnBezel);
Result.setButtonType(btnType);
end;
@ -266,6 +271,7 @@ begin
cf:=NSStringUtf8(DefEq[ADefault]);
NSButton(AButton.Handle).setKeyEquivalent(cf);
cf.release;
end;
{ TCocoaWSCustomCheckBox }
@ -422,8 +428,12 @@ begin
end;
procedure TCocoaMemoStrings.SetTextStr(const Value:string);
var
ns : NSString;
begin
fTextView.textStorage.mutableString.setString(NSStringUtf8(Value));
ns := NSStringUtf8(Value);
fTextView.textStorage.mutableString.setString(ns);
ns.release;
end;
procedure GetLineStart(const s: AnsiString; LineIndex: Integer; var Offset, LinesSkipped: Integer);
@ -524,11 +534,14 @@ class function TCocoaWSCustomMemo.CreateHandle(const AWinControl:TWinControl;
const AParams:TCreateParams):TLCLIntfHandle;
var
txt : TCocoaTextView;
ns : NSString;
scr : TCocoaScrollView;
begin
txt:=TCocoaTextView( NSView(TCocoaTextView.alloc).lclInitWithCreateParams(AParams));
txt.callback:=TLCLCommonCallback.Create(txt, AWinControl);
txt.textStorage.mutableString.setString(NSStringUtf8(AParams.Caption));
ns := NSStringUtf8(AParams.Caption);
txt.textStorage.mutableString.setString(ns);
ns.release;
scr:=EmbedInScrollView(txt);
scr.callback:=txt.callback;
Result:=TLCLIntfHandle(scr);
@ -564,10 +577,13 @@ end;
class procedure TCocoaWSCustomMemo.SetText(const AWinControl:TWinControl;const AText:String);
var
txt : TCocoaTextView;
ns : NSString;
begin
txt:=MemoTextView(AWinControl);
if not Assigned(txt) then Exit;
txt.textStorage.mutableString.setString(NSStringUtf8(AText));
ns := NSStringUtf8(AText);
txt.textStorage.mutableString.setString(ns);
ns.release;
end;
class function TCocoaWSCustomMemo.GetText(const AWinControl:TWinControl;var AText:String):Boolean;