Delphi:关闭应用程序时如何调试访问冲突?
我正在使用 Delphi 6,并且我有一个应用程序,该应用程序在关闭时会产生访问冲突错误。我们使用 EurekaLog,因此我可以获取用于调试的堆栈跟踪,但错误似乎每次都在不同的单元中随机发生,但总是在 finalization 部分中释放某些内容时发生。
我该如何进行调试以查看导致问题的原因?我不确定如何开始调试应用程序最终确定时发生的事情。
[编辑:]抱歉,如果我不清楚,也许更好的问题是:如果我只想逐步完成最终确定部分,那么使用断点开始调试的最佳位置是什么?这些错误似乎出现在我们使用的第三方组件(devexpress dx/cxgrid 库)中,因此我想在 Delphi 开始调用其他单元中的 Finalize 例程之前的最后一点开始调试我的代码。
I'm using Delphi 6 and I've got an application which when being shut down produces access violation errors. We use EurekaLog so I'm getting stack traces for debugging, but the errors seem to occur randomly in a different unit each time, but always when something is being freed in the finalization section.
How can I go about debugging this to see what's causing the problem? I'm not sure how to start debugging things that happen when the application is being finalised.
[Edit:] Sorry if I was unclear, perhaps a better question would be: What's the best place to start debugging with breakpoints if I only want to walk through the finalisation sections? The errors seem to arise in third party components we use (the devexpress dx/cxgrid library) so I'd like to start debugging in my code at pretty much the last point before Delphi will start calling finalise routines in other units.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这没什么可说的,但如果我不得不猜测,根据过去的经验……你使用的是包还是 COM 库?如果您有一个作为接口的全局变量,或者一个其类在 BPL 中声明的对象,并且您在清理对象/接口之前卸载了 DLL/BPL,那么您将遇到访问冲突,因为您的代码试图在不再映射到应用程序的地址空间中执行 VMT 查找。
检查这一点并确保在最终确定开始之前清理所有此类变量。
This isn't much to go on, but if I had to guess, based on past experience... are you using packages or COM libraries? If you've got a global variable that's an interface, or an object whose class is declared in a BPL, and you unload the DLL/BPL before cleaning up the object/interface, you'll get access violations because your code is trying to do a VMT lookup in address space that is no longer mapped into the application.
Check for that and make sure you clean up all such variables before finalization begins.
当应用程序关闭时,不要释放终结部分中的内容。
1) 当应用程序关闭时,Windows 会释放所有应用程序内存。你不必这样做。
2)当应用程序关闭时,内存被释放,基础设施被卸载。您无法调用代码来关闭或释放对象,因为该代码可能已被卸载。您无法访问内存指针,因为这些指针可能已经被释放。
3) 当您在应用程序关闭时尝试释放终结部分中的内容时,您可能会遇到阻止代码终结的故障,从而阻止应用程序关闭,从而导致应用程序挂起和内存丢失。这正是您首先想要阻止的。不要这样做。
好的,当您在Win95/98上运行或使用外部进程时,在某些情况下您可能必须释放共享资源并通知那些外部进程您正在关闭。除此之外,现在这一切都是自动发生的。
When the application is shutting down, do not free things in the finalization section.
1) When the application shuts down, Windows frees all the application memory. You don't have to do that.
2) When the application shuts down, the memory is released, and the infrastructure is unloaded. You can't call code to close or free objects, because that code may have been already unloaded. You can't access pointers to memory, because those pointers may have already been released.
3) When you try to free things in the finalization section while the application is shutting down, you may get failures that prevent your code from finalizing, thus preventing the application from shutting down, causing a hung application and memory loss. Which is what you were trying to prevent in the first place. Don't do it.
Ok, when you are running on Win95/98, or using external processes, you may in some circumstances have to free shared resources and notify those external processes that you are shutting down. Apart from that, it all happens automagically now.