[lazarus] CodeExplorer memory leak

Marc Weustink marc at dommelstein.net
Sat Nov 29 04:59:39 EST 2003

At 10:56 29-11-2003, Vincent Snijders wrote:
>I noticed the code explorer treeview has a memory leak.
>A TViewNodeData object is added to each tree node and stored in the Data
>property. When the tree node is freeed by TreeView.Items.Clear these
>TViewNodeData objects are not freeed.

This is a known issue if you use Delphi :)

>I could think of several solutions to fix this and want your input as to
>which you want.
>1. Change TTreeNode.Delete, so that it not only set Data to nil, but
>also does FData.Free if FData is an TObject. IMO this is dangerous,
>because the TreeNode might not be the owner of FData.

If so this sould be configurable. And what is Data is not an object but 
some memory to be freed. (it contains a record allocated by new)
Not the best solution

>2. Add an OnDestroy Event to TTreeNode, which the CodeExplorer can use
>to free the TViewNodeData objects. IMO, this is the best solution.

Or better add an OnNodeDestroy to the TTree, then you dont have to set 
OnDestroy on each node.
This is indeed the most generic solution.

>3. Before calling TreeView.Items.Clear in the code explorer, free and
>set to nil the data objects. Also possible, if you don't want to extend
>the LCL.

This is the common sulution in Delphi as well.

>4. Any other way, I couldn't think of.

See 2

>In what way, do you want me to supply a patch? (If you say 4., please


More information about the Lazarus mailing list