I can't figure out why I get a memory leak with this code:

I can't figure out why I get a memory leak with this code:

TMyClass = class
private
fList: TObjectList;
public
constructor Create;
destructor Destroy; override;
end;

constructor xxxx.Create;
begin
inherited
fList:=TObjectList.Create;
end;

destructor Destroy;
begin
fList.Free;
inherited;
end;

Are there any conditions (without any raised exceptions) that the above code will leak memory?

Clarification: What is leaking is fList

Comments

  1. Part of the programmers task is to be able to debug. One important aspect of debugging is to isolate the error by taking out the code under inspection into a self-contained program. Next step is to strip down the code in order to remove irrelevant parts, while still being able to reproduce the error. If you still cannot find the error, you have at least an MCVE to share.

    ReplyDelete
  2. Did you try to run the code you posted? The code you posted does not leak in Delphi 10.2, and in theory shouldn't.

    ReplyDelete
  3. John Kouraklis The question is trivial to answer once you make a MCVE.

    ReplyDelete

Post a Comment