Search code examples
delphivirtualtreeviewomnithreadlibrary

Memory Leak using VirtualTreeview and OTL


I had created a small multi threaded application and I am trying to convert it to use OmniThreadLibrary. I am using the Virtualtreeview to display a log and the status/results. The Vst Log only has two columns and the record contains just two string fields (extremely simple, no objects inside the record).

Using a DEMO project that comes with OTL (thread pool #11) I changed the project to use a VirtualTreeview instead of the listbox. When I "Run Task" from the demo there is no memory leak, but if I run "Run Task" more than once a memory leak will occur. A memory leak will occur if I run any task more than once. If I do not use the VirtualTreeView at all, no memory leaks occur at any time. Just when I use the VST and when a task is run more than once.

I do use the FreeNode event and clear the strings, and even tried using Finalize...

example:

procedure TFormMain.vstLogFreeNode(Sender: TBaseVirtualTree;
  Node: PVirtualNode);
var
  LogData: PTreeLogData;
begin
  LogData:=Sender.GetNodeData(Node);

  if Assigned(LogData) then begin
    LogData^.Msgtype := '';
    LogData^.Msg := '';
  end; 
  //Finalize(LogData^);

end;

why do I get a memory leak when a task is run more than once? Delphi 2010 with FastMM4 latest Virtualtreeview and OTL


Solution

  • The NodeFree event is only called for Validated nodes, validated usually means Nodes that are shown one or more times (when the GetText event was called). See Memory Leaks when using the Virtual TreeView Component

    edit: you can confirm by checking your node count and counting the number of times the NodeFree event is called.