Memory leak using VirtualTreeview and OTL

I have created a small multi-threaded application and I am trying to convert it to OmniThreadLibrary. I use Virtualtreeview to display log and status / results. There are only two columns in Vst Log, and a record contains only two string fields (extremely simple, with no objects inside the record).

Using the DEMO project that comes with OTL (thread pool # 11), I changed the project to use VirtualTreeview instead of a list. When I run the Task from the demo version, there is no memory leak, but if I run the 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 VirtualTreeView at all, memory leaks do not occur at any time. Just when I use VST and when a task runs more than once.

I use the FreeNode event and clear the lines and even try to use 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 completing a task more than once? Delphi 2010 with FastMM4 latest Virtualtreeview and OTL

+3
3

NodeFree Validated, , ( GetText). . Virtual TreeView

: , node , NodeFree.

+10

, , , : FastMM FullDebugMode. ( FastMM SourceForge.) , , , . , , , FastMM , . , .

+4

, FastMM4 - . CodeRage 2: . , FastMM / Delphi. D2007, .

As for why the launch proceeds twice, but does not work once, from experience it is mainly related to creating and storing an object in a field / variable without first checking, if it was assigned, the leak of the previous link. Build as follows:

TSomething
FMyObject: TMyObject;
[..]

TSomething.Destroy;
begin
  FMyObject.Free;
end;
[...]

//somewhere in code:
FMyObject := TMyObject.Create; //leaks the previous FMyObject

Obviously, this is not so simple and possibly hidden in some setters or through some list / container ... Here I would suggest adding to VirtualTreeView without checking ...

+1
source

Source: https://habr.com/ru/post/1769398/


All Articles