Last active
December 25, 2015 12:37
-
-
Save hinst/14b6e391b9598ba2b4ee to your computer and use it in GitHub Desktop.
Delphi object reference-counted strings not being released
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program Project1; | |
{$appType console} | |
uses | |
FastMM4, SysUtils; | |
type | |
TFoo = object | |
s, ss: string; // these fields are released | |
constructor Init; | |
destructor Done; virtual; | |
end; | |
PFoo = ^TFoo; | |
TDescendant = object(TFoo) | |
s2: string; // this field leaks | |
s3: string; // this field also leaks | |
constructor Init; | |
destructor Done; virtual; | |
end; | |
PDescendant = ^TDescendant; | |
{ TFoo } | |
destructor TFoo.Done; | |
begin | |
WriteLn(s); | |
WriteLN(ss); | |
end; | |
constructor TFoo.Init; | |
begin | |
s := IntToStr(42); | |
ss := IntToStr(42); | |
end; | |
procedure Lel; | |
begin | |
FastMM4.SetMMLogFileName(PAnsiChar('MM_' + FormatDateTime('yyyy-dd-mm_hh-nn-ss', Now) + '.txt')); | |
end; | |
{ TDescendant } | |
constructor TDescendant.Init; | |
begin | |
inherited Init; | |
s2 := IntToStr(43); | |
s3 := IntToStr(80085); | |
end; | |
destructor TDescendant.Done; | |
begin | |
WriteLN(s2); | |
WriteLN(s3); | |
inherited Done; | |
end; | |
var | |
f: PFoo; | |
begin | |
lel; | |
ReportMemoryLeaksOnShutdown := True; | |
f := New(PDescendant, Init); | |
Dispose(f, Done); | |
end. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment