Update of /cvsroot/instantobjects/Source/Core
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18738
Modified Files:
InstantExplorer.pas
Log Message:
1. procedure TInstantExplorer.AssignRootObject - InstantExplorer Nodedata was not freed causing memory leaks.
2. constructor TInstantExplorerNodeData.Create
destructor TInstantExplorerNodeData.Destroy
- In constructor added InstantExplorer Nodedata instance reference ownership for InstantObject types so that the Nodedata instances are not destroyed before the Nodedata is freed. Added destructor to reverse instance reference.
Index: InstantExplorer.pas
===================================================================
RCS file: /cvsroot/instantobjects/Source/Core/InstantExplorer.pas,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** InstantExplorer.pas 4 Sep 2005 23:15:54 -0000 1.4
--- InstantExplorer.pas 24 Nov 2005 23:14:11 -0000 1.5
***************
*** 25,29 ****
*
* Contributor(s):
! * Carlo Barazzetta, Adrea Petrelli, Nando Dessena
*
* ***** END LICENSE BLOCK ***** *)
--- 25,30 ----
*
* Contributor(s):
! * Carlo Barazzetta, Adrea Petrelli, Nando Dessena, Steven Mitchell,
! * Joao Morais
*
* ***** END LICENSE BLOCK ***** *)
***************
*** 66,69 ****
--- 67,71 ----
constructor Create(ANodeType: TInstantExplorerNodeType; AName: string;
AInstance: TObject; AValue: string);
+ destructor Destroy; override;
property Caption: string read GetCaption;
property ImageIndex: Integer read GetImageIndex;
***************
*** 266,272 ****
--- 268,283 ----
FName := AName;
FInstance := AInstance;
+ if FInstance is TInstantObject then
+ TInstantObject(FInstance).AddRef;
FValue := AValue;
end;
+ destructor TInstantExplorerNodeData.Destroy;
+ begin
+ if FInstance is TInstantObject then
+ TInstantObject(FInstance).Free;
+ inherited;
+ end;
+
function TInstantExplorerNodeData.GetCaption: string;
begin
***************
*** 385,388 ****
--- 396,420 ----
SaveOnChange: TTVChangedEvent;
ChildCount: Integer;
+
+ procedure FreeTreeViewNodeData(ATreeNodes: TTreeNodes);
+ var
+ Obj: TObject;
+ begin
+ with ATreeNodes do
+ begin
+ Node := GetFirstNode;
+ while Node <> nil do
+ begin
+ // Don't test 'Assigned(Node.Data)' because value
+ // of 'Node.Data' could be -1 ('NotLoaded')
+ if Integer(Node.Data) > 0 then
+ begin
+ Obj := TObject(Node.Data);
+ FreeAndNil(Obj);
+ end;
+ Node := Node.GetNext;
+ end;
+ end;
+ end;
begin
ItemIndex := 0;
***************
*** 393,396 ****
--- 425,431 ----
Items.BeginUpdate;
try
+ if Assigned(FRootObject) then
+ FreeTreeViewNodeData(Items);
+
if Assigned(Selected) then
ItemIndex := Selected.AbsoluteIndex;
|