JAM-Software / Virtual-TreeView

Virtual Treeview is a Delphi treeview control
http://www.jam-software.de/virtual-treeview/
646 stars 253 forks source link

Clarification please regarding OnFreeNode handling for strings etc #1219

Closed gwideman closed 1 month ago

gwideman commented 1 year ago

The OnFreeNode event Help doc mentions: "You should however finalize the data in such a case if it contains references to external memory objects (e.g. variants, strings, interfaces)."

Could we get a more explicit description or example of how to handle this? Does it mean calling Finalize on each individual dynamically-allocated field? Or is it possible to call a single function (possibly Finalize), passing the entire data record?

I am not 100% sure from the Embarcadero doc how to do this. The example page "System InitializeFinalize (Delphi) shows:

  PPerson = ^TPerson;
  TPerson = record
    FFirstName: String;
    FLastName: String;
    FAge: Integer;
  end;
[...]
  GetMem(Person, SizeOf(TPerson));
  Initialize(Person^);
[...]
Finalize(Person^);
FreeMem(Person);

For the TVirtualStringTree node data, I think we skip GetMem and Initialize, but in OnFreeNode we have to:

pNodeData := vst.GetNodeData(Node);
Finalize(pNodeData^);

... and I think the FreeMem is unnecessary and should not be called.

Is all that right?

Thanks.

livius2 commented 1 year ago

Simply turn on System.ReportMemoryLeaksOnShutdown:= true; in Form OnCreate and check results with and without FreeMem

joachimmarder commented 1 year ago

Please understand that we do not provide technical support for Virtual TreeView here. Please try to get support from the community e.g. at Stack Overflow , Delphi Pages or Delphi Praxis . Please do not use GitHub issues for getting support.    If you feel you found a bug, please respect our guidelines on the project homepage for submitting bugs. Please include your version of Virtual TreeView and Delphi, and attach a sample compiling project as ZIP to your report, or instructions how to modify one of the included sample projects to reproduce the problem. If only small changes are required, a description is sufficient how a demo projects needs to be changed in order to replicate the bug. If you already have a solution, please supply a patch file.