Log On
Embarcadero Home
Watch, Follow, &
Connect with Us
Share This
QualityCentral
Communities
Articles
Blogs
Resources
Downloads
Help
QualityCentral
Delphi-BCB
RTL
Delphi
Arithmetic
ConvUtils
Date - Time
DateUtils
File Management
Format + Float
Input/Output
Math Unit
Memory, Pointer, Address
Null-terminated strings
Other Classes
Other RTL
Pascal Strings
Regular Expressions
RTL Exceptions
Text Files
Thread support
Typed/Untyped Files
WinAPI
You are not logged in.
Help
Print
Public Report
Report From:
Delphi-BCB/RTL/Delphi/Null-terminated strings
[ Add a report in this area ]
Report #:
24437
Status:
Closed
memory leak using string in record type
Project:
Delphi
Build #:
10.0.2163.24987
Version:
10.0
Submitted By:
Renzo Fallani
Report Type:
Basic functionality failure
Date Reported:
2/2/2006 12:59:52 PM
Severity:
Critical / Show Stopper
Last Updated:
2/16/2006 4:41:46 PM
Platform:
All versions
Internal Tracking #:
Resolution:
Test Case Error
(Resolution Comments)
Resolved in Build:
:
None
Duplicate of:
None
Voting and Rating
Overall Rating:
(1 Total Rating)
1.00 out of 5
Total Votes:
None
Description
(sorry for my english)
FastMM report memory leak for the code described in "Steps".
If you change the declaration of TMyRec as:
TMyRec = record
aStr: WideString;
end;
declaring aStr as WideString (instead of as string), no memory leaks are reported.
Steps to Reproduce:
Create a new Win32 project with a form.
insert the code below (declaration of TMyRec, FormCreate event handler).
Execute in the IDE
Close the application.
You get a message of memory leak for every TmyRec allocated.
-----------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
type
PMyRec = ^TMyRec;
TMyRec = record
aStr: string;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
frec : PMyRec;
fList : TList;
begin
ReportMemoryLeaksOnShutdown := True;
fList := TList.Create;
for i := 0 to 1000 do
begin
new(fRec);
fRec^.aStr := 'test';
fList.Add(fRec);
end;
for i := 0 to fList.Count-1 do
begin
Dispose(fList[i]);
end;
fList.Free;
end;
end.
Workarounds
..
Attachment
None
Comments
Michael Winter at 2/10/2006 12:43:46 AM
-
No bug, the memory leak caused by you.
The compiler does have no chance to see the pointer you put into the Dispose function is a PMyRec. Therefore it can't create code to finalize the record before it's disposed.
To fix the problem, use
Dispose(PMyRec(fList[i]));
instead.
Using WideString doesn't really fix your case, it's only that FastMM isn't resonsible for WideString memory. Your application still leaks.
Renzo Fallani at 2/11/2006 8:08:39 AM
-
Yes, I agree with you. I have confused because of an other bug in a large project, and the different behaviour of string and widestring.
Regards.
View Your Reports
Search
Server Response from: ETNACODE01
Developer Tools
Blackfish SQL
C++Builder
Delphi
FireMonkey
Prism
InterBase
JBuilder
J Optimizer
HTML5 Builder
3rdRail & TurboRuby
Database Tools
Change Manager
DBArtisan
DB Optimizer
ER/Studio
Performance Center
Rapid SQL
Technical Articles
Tutorials
White Papers
Press Releases
Newsletters
Add Content (GetPublished)
Audio
Audio & Video
Video
Bugs & Suggestions (QualityCentral)
Discussion Forums
Examples (CodeCentral)
Tags
Technology Partners
Downloads
Free Trials
Registered User Downloads
Beta Programs
Add Content (GetPublished)
Articles
Blogs
Bugs & Suggestions (QualityCentral)
Discussion Forums
Examples (CodeCentral)
Member Services
About
Connect with Us