作为Vista认证的一部分,Microsoft希望确保应用程序退出而无需持有锁定(关键部分):
测试案例31.使用指定的AppVerifier检查确认应用程序不会进入调试器(请求:3.2)
事实证明,使用Delphi 2009构建的网络应用程序确实侵入了调试器,它显示了无用的消息,如下所示:
(1214.1f10): Break instruction exception - code 80000003 (first chance)
eax=00000001 ebx=07b64ff8 ecx=a6450000 edx=0007e578 esi=0017f7e0 edi=80000003
eip=77280004 esp=0017f780 ebp=0017f7ac iopl=0 nv up ei pl zr na pe nc
cs=0023 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00000246
*** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\Windows\SysWOW64\ntdll.dll -
ntdll!DbgBreakPoint:
77280004 cc int 3
多次点击Go按钮后,您会遇到实际错误:
=======================================
VERIFIER STOP 00000212: pid 0x18A4: Freeing virtual memory containing an active critical section.
076CC5DC : Critical section address.
01D0191C : Critical section initialization stack trace.
075D0000 : Memory block address.
00140000 : Memory block size.
=======================================
This verifier stop is continuable.
After debugging it use `go' to continue.
=======================================
鉴于我的代码没有泄漏TCriticalSection
,我如何阻止Delphi这样做。
答案 0 :(得分:13)
Indy10在退出时故意泄漏关键部分。
IdStack.pas:
finalization
// Dont Free. If shutdown is from another Init section, it can cause GPF when stack
// tries to access it. App will kill it off anyways, so just let it leak
{$IFDEF IDFREEONFINAL}
FreeAndNil(GStackCriticalSection);
{$ENDIF}
IdThread.pas:
finalization
// This call hangs if not all threads have been properly destroyed.
// But without this, bad threads can often have worse results. Catch 22.
// TIdThread.WaitAllThreadsTerminated;
{$IFDEF IDFREEONFINAL}
//only enable this if you know your code exits thread-clean
FreeAndNil(GThreadCount);
{$ENDIF}
%delphi_home%\source\Indy\Indy10\System
和%delphi_home%\source\Indy\Indy10\Core
复制到您的项目中,或将其包含在搜索路径中。IDFREEONFINAL
重建或删除IFDEF指令。答案 1 :(得分:0)
除非您在ReportMemoryLeaksOnShutdown := True
中运行FullDebugMode
或FastMM4以捕获所有内存泄漏(您的代码和Delphi库),否则您怎么知道您的代码没有泄漏?
在FullDebugMode中运行您的应用程序也会为您提供不同内存分配的StackTrace
您可能会发现,实际上,您正在泄漏IdStack关键部分。
您可能需要查看此CodeRage 2会话:Fighting Memory Leaks for Dummies。它主要说明如何使用FastMM来防止/检测Delphi中的内存泄漏。适用于D2007,但仍与D2009相关。