小编SCA*_*son的帖子

TList中的内存泄漏

使用TList时出现内存泄漏问题.我试图填充填充列表中的Tlist循环并使用数据.下面的代码只是填充列表而不使用它的代码.

private
  { Private Form Variable declarations }
  GlblCancel : Boolean;
  MyPrintLst : TList;

PrintRecord = record
  PrintString1,
  PrintString2,
  PrintString3,
  PrintString4,
  PrintString5,
  PrintString6 : string;
  PrintFloat1,
  PrintFloat2,
  PrintFloat3  : Double;
end;
PrintPointer = ^PrintRecord;

Procedure TMyForm.Create;
begin
  MyPrintLst := TList.Create;
end

Procedure TMyForm.FreeTList(Var List : Tlist; Size : Integer);
Var I, Count : Integer;
begin
  Count := list.Count - 1;
  For I := Count DownTo 0 Do
     FreeMem(List[I], Size);
  List.Clear;
  List.Free;
end;

Procedure TMyForm.FormClose;
begin
  FreeTList(MyPrintLst,SizeOf(PrintRecord));
end

procedure AddToPrintList(PrintList : …
Run Code Online (Sandbox Code Playgroud)

delphi delphi-7

1
推荐指数
1
解决办法
308
查看次数

使用tlist在完整Delphi代码中泄漏内存

附件是我遇到的内存泄漏示例的完整代码.有人可以告诉我如何清理这个内存泄漏.如果您创建一个表单并在其上放置一个按钮,然后将下面的代码粘贴到.pas文件中,则可以编译此代码.提前感谢您提供的任何帮助.

unit LeakForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
type PrintRecord = record
  PrintString1,
  PrintString2,
  PrintString3,
  PrintString4,
  PrintString5,
  PrintString6 : string;
  PrintFloat1,
  PrintFloat2,
  PrintFloat3  : Double;
end;
PrintPointer = ^PrintRecord;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
    MyPrintLst : TList;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
procedure ClearTList(Var List : TList);
Var …
Run Code Online (Sandbox Code Playgroud)

delphi memory-leaks delphi-7

1
推荐指数
1
解决办法
484
查看次数

标签 统计

delphi ×2

delphi-7 ×2

memory-leaks ×1