[lazarus] CodeExplorer memory leak

Vincent Snijders vslist at zonnet.nl
Sat Nov 29 08:33:07 EST 2003

On Sat, 29 Nov 2003 11:10:17 +0100
Marc Weustink <marc at dommelstein.net> wrote:

> At 10:56 29-11-2003, Vincent Snijders wrote:
> >Hi,
> >
> >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
I will do so.


More information about the Lazarus mailing list