Skip to content

Commit ac4b935

Browse files
author
Joachim Marder
committed
Fixed mem leak described in issue #34.
1 parent 37f375f commit ac4b935

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

Lib/UIRibbonCommands.pas

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,7 @@ TEnumerator = class
10671067
public
10681068
{ Creates a new empty collection }
10691069
constructor Create; overload;
1070+
destructor Destroy; override;
10701071

10711072
{ Creates a collection based on an exiting IUICollection object }
10721073
constructor Create(const Handle: IUICollection); overload;
@@ -1123,7 +1124,7 @@ TUIGalleryCollectionItem = class(TUICollectionItem)
11231124
function GetPropertyValue(const Prop: TUIProperty): TValue; override;
11241125
{$ENDREGION 'Internal Declarations'}
11251126
public
1126-
constructor Create;
1127+
constructor Create(const pLabel: String = ''; const pImage: IUIImage = nil);
11271128

11281129
{ The label text for the item. Used for Items and Categories. }
11291130
property LabelText: String read FLabel write FLabel;
@@ -2407,9 +2408,6 @@ procedure TUICommandCollection.Notify(const Flag: Integer);
24072408
begin
24082409
UIInitPropertyFromInterface(UI_PKEY_ItemsSource, FItems.Handle, Val);
24092410
FFramework.SetUICommandProperty(FCommandId, UI_PKEY_ItemsSource, Val);
2410-
{ The ribbon takes additional ownership of the collection, so we must
2411-
release it to avoid a memory leak. }
2412-
FItems.Handle._Release;
24132411
end;
24142412

24152413
NOTIFY_CATEGORIES:
@@ -3789,6 +3787,15 @@ procedure TUICollection.Delete(const Index: Integer);
37893787
Changed;
37903788
end;
37913789

3790+
destructor TUICollection.Destroy;
3791+
begin
3792+
{ The ribbon takes additional ownership of the collection, so we must
3793+
release it to avoid a memory leak. See issue #34 }
3794+
while FHandle._Release() > 1 do;
3795+
FHandle := nil;
3796+
Inherited;
3797+
end;
3798+
37923799
procedure TUICollection.EndUpdate;
37933800
begin
37943801
Dec(FUpdateCount);
@@ -3975,9 +3982,11 @@ function TUICollection.TEnumerator.MoveNext: Boolean;
39753982

39763983
{ TUIGalleryCollectionItem }
39773984

3978-
constructor TUIGalleryCollectionItem.Create;
3985+
constructor TUIGalleryCollectionItem.Create(const pLabel: String = ''; const pImage: IUIImage = nil);
39793986
begin
39803987
inherited Create;
3988+
FLabel := pLabel;
3989+
FImage := pImage;
39813990
FCategoryId := UICollectionInvalidIndex;
39823991
end;
39833992

0 commit comments

Comments
 (0)