来自delphi xe8的未知内存泄漏
我创建了一个简单的应用程序,表单Tform1上有一个按钮,用于创建另一个表单Tform2。Form2包含一个工具栏,每个角落有两个按钮,以及一个标签,其下方有一个tabcontrol。我一直在下面发现内存泄漏。我确信我正确地创建和销毁了表单 下面是创建form2的form1来自delphi xe8的未知内存泄漏,delphi,memory-leaks,firemonkey,delphi-xe8,Delphi,Memory Leaks,Firemonkey,Delphi Xe8,我创建了一个简单的应用程序,表单Tform1上有一个按钮,用于创建另一个表单Tform2。Form2包含一个工具栏,每个角落有两个按钮,以及一个标签,其下方有一个tabcontrol。我一直在下面发现内存泄漏。我确信我正确地创建和销毁了表单 下面是创建form2的form1 unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
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
正如我在评论中所说,我无法用您显示的代码重现内存泄漏报告。但也许你找错人了,所以我来试试猜 你从来没有解释过你为什么要这样对待
表单1
,但我有一种奇怪的感觉,那可能是一个登录表单。如果是这样的话,我将按如下方式进行:
项目1.dpr
program Project1;
uses
System.StartUpCopy,
FMX.Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2},
System.UITypes; // for the modal result
{$R *.res}
begin
ReportMemoryLeaksOnShutdown := True;
Application.Initialize;
Form1 := TForm1.Create(Application);
try
if Form1.ShowModal <> System.UITypes.mrOK then
Exit;
finally
Form1.Free;
end;
Application.CreateForm(TForm2, Form2);
Application.Run;
end.
如果这根本不是您想要的,请告诉我,我将删除。使用完整的快速MM版本获取与分配相关的堆栈跟踪。但是,看起来您关闭了主窗体两次。@DavidHeffernan我在创建第二个窗体2后隐藏了第一个窗体,然后使用Application.mainform.close从窗体2关闭主窗体。close想知道我在哪里关闭主窗体两次我不认为这是Delphi版本的问题,我尝试了XE8,没有内存泄漏。“与界面交互”是什么意思?在UI中几乎没有可交互的内容。您的代码是否与此处显示的代码完全相同?我倾向于用一个简单的规则进行设计:“无论什么创造,也会破坏”,所以我不会从第二个表单中终止应用程序。但这似乎不是你的问题。如果我们不能重现这一点,我们如何帮助你。也许您需要创建一个。
189-204字节:TApplication x 1
这意味着进程异常终止谢谢=)。你说得对,我有一个通过unidac使用数据库连接的登录表单。上述方法可以将登录表单作为模式表单处理。我再也没有收到那个错误了。@kami在Tedit
s中没有闪烁的光标。我测试了你关于重新分配Application.Mainform
的建议(在一次链接讨论中),结果一切正常。因此,另一种方法是正常创建两个表单(首先使用loginform),如果登录成功,则更改主表单并释放登录表单。有趣的是,文档中说“MainForm不能在运行时修改(它在运行时是只读的)”。似乎是文档错误。@TomBrunberg,谢谢!我只想知道XE7/8上的“原始”行为
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.
program Project1;
uses
System.StartUpCopy,
FMX.Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2},
System.UITypes; // for the modal result
{$R *.res}
begin
ReportMemoryLeaksOnShutdown := True;
Application.Initialize;
Form1 := TForm1.Create(Application);
try
if Form1.ShowModal <> System.UITypes.mrOK then
Exit;
finally
Form1.Free;
end;
Application.CreateForm(TForm2, Form2);
Application.Run;
end.
procedure TForm1.Button1Click(Sender: TObject);
begin
if (Edit1.Text = 'User') and (Edit2.Text = 'pass') then
modalresult := System.UITypes.mrOK;
end;