Monday, December 17, 2007

Memory Leak and Real time memory (object) allocation monitoring

I like the way Delphi handles its object especially the ownership of the object. We tend to use MyComponent.Create(Owner) constructor to attach the object to an owner. Whenever the owner is disposed, the owner will dispose its children, in this case MyComponent. If MyComponent is not disposed, you might end up in a situation where your software is eating up memory every now and then. This is what we call memory leak. Delphi 2007 comes with an efficient memory manager to report memory leakage upon shut down by assigning ReportMemoryLeaksOnShutdown to True.

With Garbage Collector in .Net platform, all memory leak headache has been set aside and developers can now focus on implementing the business logic rather than trying to address the memory leak issue.

Let's go back to Win32 platform. Recently, I have developed a software for Fan Control System and my customer expects it to run 7x24 with minimum downtime. I guess memory leak is an issue here as I don't want my software to eat up memory over the time. So I have got the ReportMemoryLeaksOnShutdown set to True in my main form OnCreate event.
In addition, I let my software ran in a separate machine for a period of time with my Task Manager window on. From time to time, I took down the memory usage of my software (well, I was embarking the most primitive way) but I wasn't contented. I needed to know the true picture of memory/object allocation during the runtime. I searched the internet and found AQTime from AutomatedQA and downloaded the trial version. It worked perfectly and I was able to know the object allocation real time.

Is there a Garbage Collector for Delphi Win32? Read the article from Borland http://dn.codegear.com/article/28217 to find out more.

No comments: