Delphi 7 和 Delphi 2007 中接口的区别

发布于 2024-10-23 23:59:54 字数 461 浏览 2 评论 0原文

我们遇到了仅在应用程序运行时发生的内存泄漏问题(当我们关闭应用程序时没有 FastMM 报告)。

我们将问题隔离到从数据库读取值并从结果中实例化对象的方法。 (我们使用 DBXPress 来连接数据库)

执行数据库操作的类实现了一个接口。 使用除了运行从数据库读取值(始终相同的值)的线程之外不执行任何其他操作的测试应用程序,Delphi 7 中的应用程序不会泄漏。但在 Delphi 2007 中,内存使用量跳跃得非常快。这是相同的代码,相同的测试应用程序。

当您使用 AQTime 检查应用程序时,您可以看到 TStringList、TList 等(数据库类使用的所有对象)的数量增长和收缩 - 但使用 ProExplorer 和 Windows 任务管理器检查内存时,Delphi 2007 版本增长得非常快。

我们唯一的猜测是 Delphi 7 和 Delphi 2007 处理接口发布的方式有所不同。有道理吗?有人经历过类似的事情吗?

We are having trouble with a memory leak that happens only when the application is running (there is no FastMM report when we close the application).

We isolate the problem to a method that reads values from a database and instantiate objects from the result. (we are using DBXPress to database connection)

The class that do the database stuff implements an interface.
Using a test application that does nothing else but run a thread reading values from the database (always the same values), the application in Delphi 7 do not leak. But in Delphi 2007 the memory used jumps really fast. It is the same code, same test application.

When you check the application with AQTime you can see the number of TStringList, TList, etc (all the objects the database class uses) growing and shrink - but checking the memory with ProExplorer and with Windows task manager, the Delphi 2007 version grows really fast.

Our only guess is that there is something different in the way Delphi 7 and Delphi 2007 deals with interface releasing. Does it make sense? Anyone had experienced something similar?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怀里藏娇 2024-10-30 23:59:54

嗯...我的 2 美分:

delphi 2007 的界面工作方式没有什么不同。但很久以前,我在接口方面遇到了类似的问题,最终我根本没有使用接口引用计数。它的效果不太好。

您没有发布源代码,但我猜您实现该接口的对象继承自 TInterfacedOject,对吗?如果是这样,请考虑将其更改为您自己的 TInterfacedObject,该对象不会实现引用计数方法。你将不得不销毁你的对象,而不是让delphi处理它们。

您可能考虑的另一件事是通过将您不使用的接口对象设置为 nil 来告诉 delphi 您不再需要该接口对象。

但正如大家在评论中所说,如果 fastmm 没有报告泄漏,那么根本就没有泄漏。内存快速增长的事实并不表明您的程序正在泄漏。它只是说你没有按照你想要的方式关注你的物体。

您应该使用 EurekaLog。这是一个非常好的插件,可以报告内存泄漏及其调用堆栈。

另外,看看这个问题

Well... My 2 cents:

There is nothing diffent in the way delphi 2007 works with interfaces. But a long time ago i had a similar issue with interfaces, and i ended up not using the interface reference count at all. It does not work really well.

You did not post you source, but i guess your objects that implements the interface are inheriting from TInterfacedOject, am i right? If so, consider changing it to you own TInterfacedObject that will not implement the reference count methods. You will have to destroy your objects, instead of having delphi deal with them.

Another thing you might consider is to tell delphi you are no longer needing the interfaced object, by setting nil to the interfaced object you are not using.

But as everybody said on comments, if fastmm is not reporting a leak, them there are no leaks at all. The fact that the memory is growing fast do not indicate that your program are leaking. It only says that you are not pay attention on your objects as you wanted to.

You should use EurekaLog. It is a very good addon that reports memory leaks and their callstack.

Also, take a look at this Question

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文