开发者

Difference between Interfaces in Delphi 7 and 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 gue开发者_运维知识库ss 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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜