[lazarus] CodeExplorer memory leak

Vincent Snijders vslist at zonnet.nl
Sat Nov 29 04:45:28 EST 2003


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.

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.

2. Add an OnDestroy Event to TTreeNode, which the CodeExplorer can use
to free the TViewNodeData objects. IMO, this is the best 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. 
4. Any other way, I couldn't think of.

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


More information about the Lazarus mailing list