【发布时间】:2016-03-07 07:35:15
【问题描述】:
我创建了一个简单的应用程序,它在表单 Tform1 上带有一个按钮,用于创建另一个表单 Tform2。 Form2 包含一个工具栏,每个角落有 2 个按钮,标签下方有一个 tabcontrol。我一直在下面得到这个内存泄漏。我确定我正确地创建和销毁了表单。
program Project1;
uses
System.StartUpCopy,
FMX.Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2};
{$R *.res}
begin
ReportMemoryLeaksOnShutdown := True;
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
这里是创建form2的form1
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
FMX.Controls.Presentation, FMX.StdCtrls, Unit2;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.Button1Click(Sender: TObject);
begin
Hide;
Application.CreateForm(TForm2, Form2);
Form2.Show;
Form2.WindowState := TWindowState.wsMaximized;
end;
end.
带有工具栏和选项卡控件的表单 2
unit Unit2;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
FMX.TabControl, FMX.Controls.Presentation;
type
TForm2 = class(TForm)
ToolBar1: TToolBar;
Button1: TButton;
TabControl1: TTabControl;
TabItem1: TTabItem;
TabItem2: TTabItem;
Label1: TLabel;
Button2: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.fmx}
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := TCloseAction.caFree;
// ShowMessage('Form Freed now closing whole application') ;
Application.MainForm.Close;
end;
end.
【问题讨论】:
-
使用完整的快速 MM 版本来获取与分配相关的堆栈跟踪。但是,您似乎关闭了主窗体两次。
-
@DavidHeffernan 我只是在创建第二个 form2 后隐藏了第一个表单,然后使用 Application.MainForm.Close 从 form2 关闭主窗体,想知道我在哪里关闭了主窗体两次
-
我不认为这是Delphi版本的问题,我尝试使用XE8并且没有内存泄漏。 “与界面交互”是什么意思? UI 中几乎没有可交互的内容。您是否拥有与此处提供的完全相同的代码?我倾向于使用一个简单的规则进行设计:“无论创造什么,都会破坏”,所以我不会从辅助形式中删除应用程序。不过,这似乎不是你的问题。
-
如果我们无法重现这一点,我们该如何提供帮助。也许您需要创建一个minimal reproducible example。
-
189-204 bytes: TApplication x 1表示进程异常终止
标签: delphi memory-leaks firemonkey delphi-xe8