Link to home
Start Free TrialLog in
Avatar of fischermx
fischermxFlag for Mexico

asked on

Checking for memory leaks in Delphi XE application


I was a long user of Memproof... correction I am still a user of Memproof, and I use it in two old applications I still maintain, one in Delphi 5 other in Delphi 7.

Now, I'm doing some weird pointer operations (weird cause I'm not an expert) in a new project I started in Delphi XE.
I compiled and try to run with Memproof and I get nothing... looks like memproof can't hook into this Delphi application.
I supose its simply because it was writing long before this particular Delphi version, it's just not prepared for that.

Now, I did some research and found recommendations for FastMM, and EurekaLog.... non of them look similar to memproof...
Well, first question here, are these the only two options? What else?

And next one, in this Delphi XE, it installed a version of AutomatedQA AQTime, and I remember I once used that for memory leaks when a contractor provide me a license of that for certain project. Now I look at what I have installed, and I not even know where to start, seems like this included version does not the memory leak checking thing... does it?






ASKER CERTIFIED SOLUTION
Avatar of samenglish
samenglish
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fischermx

ASKER


Well, the I was not looking for a nice GUI exactly, but with memproof I liked you can link the code and get a reference directly to the offending leak.


With FastMM all I got was a text file =) but well, I've just found one leak in my code and fixed it, but it is because it's a few dozens lines of code with more lines you'd get lost.

It just tells you the class name and the amount of leaks, so, for example, if you have an leak on a TList and have lots of that class in your code, how do you know which is the leaked one?

Another one I've used in the past is MadExcept http://www.madshi.net/   
It did the job for me at the time.

With FastMM, there are some special switches you need to set. I think what you really need is a good link that walks you through the process of using FastMM.

http://wiert.wordpress.com/2009/07/29/delphi-fastmm-using-fastmm4-for-debugging-your-memory-allocations-part-1-introduction/

However, if you're familiar with FastMM and you're having issues because it's Delphi XE then please let me know.
I am using MadExcept right now.
But it didn't report me any memory leak.

How, where, do I configure it for memory leak checks?
I'm using it just as an exception catcher.

MadExcept is just good at catching bad code, not necessarily memory leaks. Make sure you're on the latest version for XE support.

If you're serious about memory leaks I'd go with FastMM. You need to set FullDebugMode. (refer to link provided in previous post)

In your code, you need to make sure that every object you create at runtime will also be destroyed at runtime. So use this pattern repeatedly throughout your methods, and pass parameters by reference rather than have function return dynamically created objects (it makes it easier to see the obj being created, so that you remember to destroy it when it has served its purpose).

MyObj.Create
try
  // you code
finally
  MyObj.Free; // or FreeAndNil(MyObj);
end;
also here http://stackoverflow.com/questions/6075554/how-do-i-turn-on-off-fastmm-memory-leak-reporting-under-delphi-xe

NOTE: Delphi XE's integrated FastMM is not as powerful as the seperate FastMM download. The FastMM download is configurable for XE the same way it is done with earlier versions of Delphi (refer to link previously provided).
Thank you!

FastMM has been of great help.