delphi 退出程序_程序退出时Delphi中的内存泄漏通知

delphi 退出程序

All Delphi versions since Delphi 2006 have an updated memory manager that is faster and more feature rich.

自Delphi 2006以来,所有Delphi版本均具有更新的内存管理器,该管理器速度更快且功能更丰富。

One of the nicest features of the "new" memory manager allows applications to register (and unregister) expected memory leaks, and optionally report unexpected memory leaks on program shutdown.

“新”内存管理器最好的功能之一是允许应用程序注册(和注销)预期的内存泄漏,并有选择地在程序关闭时报告意外的内存泄漏。

When creating WIN32 applications with Delphi it is imperative to make sure that you free all the objects (memory) you create dynamically.

使用Delphi创建WIN32应用程序时,必须确保释放动态创建的所有对象(内存)。

A memory (or resource) leak occurs when the program loses the ability to free the memory it consumes.

当程序失去释放其消耗的内存的能力时,就会发生内存(或资源)泄漏

报告关机时的内存泄漏 ( Report Memory Leaks on Shutdown )

Memory leak detecting and reporting are set to false by default. To enable it, you need to set the global variable ReportMemoryLeaksOnShutdown to TRUE.

默认情况下,内存泄漏检测和报告设置为false。 要启用它,您需要将全局变量ReportMemoryLeaksOnShutdown设置为TRUE。

When the application is closed, if there are unexpected memory leaks the application will display the "Unexpected Memory Leak" dialog box.

当应用程序关闭时,如果发生意外的内存泄漏,则应用程序将显示“意外的内存泄漏”对话框。

The best place for the ReportMemoryLeaksOnShutdown would be in the program's source code (dpr) file.

ReportMemoryLeaksOnShutdown的最佳位置将在程序的源代码(dpr)文件中。

begin
  ReportMemoryLeaksOnShutdown := DebugHook <> 0;
  //source "by" Delphi
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TMainForm, MainForm) ;
  Application.Run;
end.

Note: a global variable DebugHook is used above to make sure memory leaks are displayed when the application is run in debug mode - when you fit F9 from the Delphi IDE.

注意:上面使用全局变量DebugHook来确保在调试模式下运行应用程序时显示内存泄漏-当您从Delphi IDE安装F9时。

测试驱动器:内存泄漏检测 ( Test Drive: Memory Leak Detection )

Having ReportMemoryLeaksOnShutdown set to TRUE, add the following code in the main form's OnCreate event handler.

将ReportMemoryLeaksOnShutdown设置为TRUE,在主窗体的OnCreate事件处理程序中添加以下代码。

var
  sl : TStringList;
begin
  sl := TStringList.Create;
  sl.Add('Memory leak!') ;
end;

Run the application in debug mode, exit the application - you should see the memory leak dialog box.

在调试模式下运行该应用程序,退出该应用程序-您应该看到内存泄漏对话框。

Note: If you are looking for a tool to catch your Delphi application errors such as memory corruption, memory leaks, memory allocation errors, variable initialization errors, variable definition conflicts, pointer errors ... take a look at madExcept and EurekaLog

注意:如果您正在寻找一种工具来捕获您的Delphi应用程序错误,例如内存损坏,内存泄漏,内存分配错误,变量初始化错误,变量定义冲突,指针错误...请查看madExcept和EurekaLog

Delphi提示导航器 ( Delphi Tips Navigator )

翻译自: https://www.thoughtco.com/memory-leak-notification-in-delphi-1057613

delphi 退出程序

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值