Delphi VCL Memory Leak?

I am dealing with a slow memory leak that causes a massive program to fail after more than a week running. So I started a leak hunt by stripping down the app to the first self written unit and checking. Low and Behold, it leaked. So I started with just a bare bones App - frame only, and it Leaked. I have duplicated it on Delphi 6 and on Borland Developer Studio 2006. Start with a new VCL app. Add nothing, but compile and run. Now Ctrl-alt-Del and set up to watch the memory of your empty app with out overl
apping the app screen. Now click on your app and watch the memory size grow with every click. The OS is attaching the message (about 16k) to the app with every click and it is not being released! It could be happening with every system message. My app runs in about 250meg on a 1 gig machine and starts misbehaving after a week or two running. Right now my fix is to blame Microsoft and ask the clients to reboot the machine every week. But I wonder???

Edited by: David Sparkman on Jan 4, 2009 4:35 AM
0
David
1/4/2009 12:35:26 PM
embarcadero.delphi.general 4258 articles. 0 followers. Follow

14 Replies
1578 Views

Similar Articles

[PageSpeed] 24

David Sparkman wrote:
> I am dealing with a slow memory leak that causes a massive program to fail after more than a week running. So I started a leak hunt by stripping down the app to the first self written unit and checking. Low and Behold, it leaked. So I started with just a bare bones App - frame only, and it Leaked. I have duplicated it on Delphi 6 and on Borland Developer Studio 2006. Start with a new VCL app. Add nothing, but compile and run. Now Ctrl-alt-Del and set up to watch the memory of your empty app with out ove
rl
> apping the app screen. Now click on your app and watch the memory size grow with every click. The OS is attaching the message (about 16k) to the app with every click and it is not being released! It could be happening with every system message. My app runs in about 250meg on a 1 gig machine and starts misbehaving after a week or two running. Right now my fix is to blame Microsoft and ask the clients to reboot the machine every week. But I wonder???
> 
> Edited by: David Sparkman on Jan 4, 2009 4:35 AM

Task manager is a very poor way to monitor reserved memory. Perhaps the 
memory is allocated to your process, freed at the application level, but 
not released into the free memory pool. When memory is required by other 
processes, Windows may automatically shrink the unused memory allocation 
of your process.

Cheers,
Nicholas Sherlock
0
Nicholas
1/4/2009 12:45:04 PM
David Sparkman wrote:

> I am dealing with a slow memory leak

In Delphi 2006 (and higher), you can use the new memory manager (FastMM) 
to display memory leaks at the end of program execution. Add these lines 
  at the beginning of the project source

{$WARN SYMBOL_PLATFORM OFF}
   ReportMemoryLeaksOnShutDown := DebugHook <> 0;
{$WARN SYMBOL_PLATFORM ON}

A message box will appear if you run the application in the IDE and 
terminate it.

For more detailled information about detected memory leaks and other 
memory related problems, you can use the FastMM4 distribution, which is 
available at sourceforge.net

See also:

Mastering Delphi Update for Delphi 2006
http://www.marcocantu.com/md2005/UpdateDelphi2006_ch05.html


Hope this helps
-- 
Michael Justin
SCJP, SCJA
betasoft - Software for Delphi™ and for the Java™ platform
http://www.mikejustin.com - http://www.betabeans.de
0
Michael
1/4/2009 12:59:52 PM
> 
> Task manager is a very poor way to monitor reserved memory. Perhaps the 
> memory is allocated to your process, freed at the application level, but 
> not released into the free memory pool. When memory is required by other 
> processes, Windows may automatically shrink the unused memory allocation 
> of your process.
> 
> Cheers,
> Nicholas Sherlock

Your recommendation would be? I have another app with a much more rapid memory leak, but if I can't see past this one, then finding the other will be difficult.
Thanks
David Sparkman
0
David
1/4/2009 1:01:13 PM
<David Sparkman> schreef in bericht news:62497@forums.codegear.com...
>I am dealing with a slow memory leak that causes a massive program to fail 
>after more than a week running. So I started a leak hunt by stripping down 
>the app to the first self written unit and checking. Low and Behold, it 
>leaked. So I started with just a bare bones App - frame only, and it 
>Leaked. I have duplicated it on Delphi 6 and on Borland Developer Studio 
>2006. Start with a new VCL app. Add nothing, but compile and run. Now 
>Ctrl-alt-Del and set up to watch the memory of your empty app with out 
>overl
> apping the app screen. Now click on your app and watch the memory size 
> grow with every click. The OS is attaching the message (about 16k) to the 
> app with every click and it is not being released! It could be happening 
> with every system message. My app runs in about 250meg on a 1 gig machine 
> and starts misbehaving after a week or two running. Right now my fix is to 
> blame Microsoft and ask the clients to reboot the machine every week. But 
> I wonder???
>
> Edited by: David Sparkman on Jan 4, 2009 4:35 AM

This may not be a leak that's under your control.
To check if your application itself is leaking, you can use memcheck from 
http://v.mahon.free.fr/pro/freeware/memcheck
It will report if you've created objects without freeing them and allocated 
memory without deallocating it - at program end.

Tom
0
Tom
1/4/2009 1:01:32 PM
David Sparkman wrote:
>> Task manager is a very poor way to monitor reserved memory. Perhaps the 
>> memory is allocated to your process, freed at the application level, but 
>> not released into the free memory pool. When memory is required by other 
>> processes, Windows may automatically shrink the unused memory allocation 
>> of your process.
> 
> Your recommendation would be? I have another app with a much more rapid memory leak, but if I can't see past this one, then finding the other will be difficult.

"Process explorer" gives far more detailed information. Unfortunately, 
I'm not certain which metric out of the many of process explorer is the 
best for this sort of analysis. Perhaps "private bytes". Even better is 
probably to get the Delphi memory manager to report allocated memory 
usage itself. That should be an accurate count of the bytes that Delphi 
thinks belongs to it.

Cheers,
Nicholas Sherlock
0
Nicholas
1/4/2009 1:19:41 PM
David Sparkman wrote:

> I am dealing with a slow memory leak that causes  massive program to
> fail after more than a week running. So I started a leak hunt by
> stripping down the app to the first self written unit and checking.
> Low and Behold, it leaked. So I started with just a bare bones App -
> frame only, and it Leaked. I have duplicated it on Delphi 6 and on
> Borland Developer Studio 2006.

I cannot reproduce this with D2006 (10.0.2558.35231) on a XP SP3
machine. But I'm not surprised I do have a couple of apps "in the
field" which run 24/7.

> But I wonder???

Maybe it something installed on your system which does this?

Can you provide a test case or is it really just a new VCL app with
just the one form causing this?

-- 
Pieter

"I'm in shape. Round is a shape." -- George Carlin
0
Pieter
1/4/2009 1:49:29 PM
>>
Start with a new VCL app. Add nothing, but compile and run. Now Ctrl-alt-Del 
and set up to watch the memory of your empty app with out overlapping the 
app screen. Now click on your app and watch the memory size grow with every 
click.
<<

I can't reproduce this.  Here are my steps, after a fresh start of Delphi 
2007:

Click 'New Project...' on the startup page
Click the 'VCL Forms Application' and OK
Click Project | Compile Project1 menu
Click the green Run button

Start Task Manager and move it away from the app screen and the Delphi 
Screen.  At this point Project1.exe is showing Memory (Private Working Set) 
of 1,512K.

Clicking repeatedly on the empty 'Form1' makes no difference to that figure 
of 1,512K.

Have I failed to reproduce your scenario correctly?

SteveT
0
Steve
1/4/2009 1:54:26 PM
> {quote:title=Steve Thackery wrote:}{quote}
> >>
> Start with a new VCL app. Add nothing, but compile and run. Now Ctrl-alt-Del 
> and set up to watch the memory of your empty app with out overlapping the 
> app screen. Now click on your app and watch the memory size grow with every 
> click.
> <<
> 
> I can't reproduce this.  Here are my steps, after a fresh start of Delphi 
> 2007:
> 
> Click 'New Project...' on the startup page
> Click the 'VCL Forms Application' and OK
> Click Project | Compile Project1 menu
> Click the green Run button
> 
> Start Task Manager and move it away from the app screen and the Delphi 
> Screen.  At this point Project1.exe is showing Memory (Private Working Set) 
> of 1,512K.
> 
> Clicking repeatedly on the empty 'Form1' makes no difference to that figure 
> of 1,512K.
> 
> Have I failed to reproduce your scenario correctly?
> 
> SteveT

Might be the version, I'm using Studio 6, might be I have it set to load all used units in to the compiled version. My tests, repeated just now show
6,560k no click
6,568k one click
6,604k two clicks 
6,620 three clicks
each click had 10 to 20 seconds delay to allow any system clean up of which there were none.

Others here say that this is not a good test of a memory leak. It may still just be the OS. I am running XPMedia, but have seen it also on XP Professional at various customer's.

David Sparkman
0
David
1/4/2009 2:31:20 PM
David Sparkman wrote:

> Your recommendation would be? I have another app with a much more
> rapid memory leak, but if I can't see past this one, then finding the
> other will be difficult.  Thanks David Sparkman


Have you taken a look at the fastmm memory functions? it will report
leaks..

-- 
Liz the Brit
Delphi things I have released: http://www.xcalibur.co.uk/DelphiThings
0
Liz
1/4/2009 3:00:30 PM
David Sparkman wrote:

> Your recommendation would be?

You can get a trial version of AQTime from AutomatedQA.

There is a free utility here (I've not used it recently)...

http://v.mahon.free.fr/pro/freeware/memcheck/

Eric
0
Eric
1/4/2009 4:54:46 PM
David Sparkman wrote:
> I am dealing with a slow memory leak that causes a massive program to fail after more than a week running. So I started a leak hunt by stripping down the app to the first self written unit and checking. Low and Behold, it leaked. So I started with just a bare bones App - frame only, and it Leaked. I have duplicated it on Delphi 6 and on Borland Developer Studio 2006. Start with a new VCL app. Add nothing, but compile and run. Now Ctrl-alt-Del and set up to watch the memory of your empty app with out ove
rl
> apping the app screen. Now click on your app and watch the memory size grow with every click. The OS is attaching the message (about 16k) to the app with every click and it is not being released! It could be happening with every system message. My app runs in about 250meg on a 1 gig machine and starts misbehaving after a week or two running. Right now my fix is to blame Microsoft and ask the clients to reboot the machine every week. But I wonder???
>
> Edited by: David Sparkman on Jan 4, 2009 4:35 AM
>   
I have found in my case, and this does not mean that other things can 
cause a memory leak.

If you have objects attached to a Tstringlist and do not free them upon 
deleting the string that the object is attached to
the object is left hanging around - - Mem Leak

and other one that burned me quite badly and I have to thank the experts 
here for their help. - - Thanks Peter and others.

Returning an object from a function - - if the object is created in the 
function
the calling routine must remember to free the object.  So I never do this.

Create the object first - - pass as Var, and return as Var.

These are the two main things that have bit me.

Objects that are created and not freed. - - - ugh hate this - - - easy 
to have happen.
Done it more than once myself - - 250 Meg program means lots of code so 
- - - I feel for you.

Jim P
0
Jim
1/5/2009 2:17:53 AM
"Jim P" <Jim_P@mad.scientist.com> wrote:
> I have found in my case, and this does not mean that other things can
> cause a memory leak.
>
> If you have objects attached to a Tstringlist and do not free them upon
> deleting the string that the object is attached to
> the object is left hanging around - - Mem Leak
>
> and other one that burned me quite badly and I have to thank the experts
> here for their help. - - Thanks Peter and others.
>
> Returning an object from a function - - if the object is created in the
> function
> the calling routine must remember to free the object.  So I never do this.
>
> Create the object first - - pass as Var, and return as Var.
>
> These are the two main things that have bit me.
>
> Objects that are created and not freed. - - - ugh hate this - - - easy
> to have happen.

Memcheck (http://v.mahon.free.fr/pro/freeware/memcheck) will point these out 
flawlessly. It is really a very useful unit and you don't have to change 
anything to your program. (My experience is with D6).
Tom
0
Tom
1/5/2009 11:33:10 AM
Thanks for all the help. I have downloaded both memory leak checkers and read though the code and explanations. I have a road trip to make to pay the bills, but will get on with testing these out the last half of the week. 

Again thanks all for the insights. Like Jim, I never pass objects to functions, just pointers to already created objects. I may be guilty of mass manipulation of tString lists. I will check that out. Some tStrings have up to 20,000 strings (customer Part Numbers).

The program runs so large because of large data arrays and because for speed I load older file structures of records into memory as an array of records for fast indexing. Using large block reads is so much faster than reading individual records. FYI I found a roadblock in reading files from a network, that the block read hits a 10 meg barrier on a Microsoft server. So I break the read down into multiple 10 meg or less reads. The net results is that I can read, shell sort and restructure, and rewrite a 200
,000 record file and index in 20 seconds instead of 40 minutes on a 100 mbps network. The code is only 70,000 lines (gulp) long and growing...

David Sparkman

Edited by: David Sparkman on Jan 5, 2009 6:14 AM
0
David
1/5/2009 2:15:21 PM
> {quote:title=Jim P wrote:}{quote}
> If you have objects attached to a Tstringlist and do not free them upon 
> deleting the string that the object is attached to
> the object is left hanging around - - Mem Leak

This bit me once or twice (or so...).  I built my own library routine to clean them up properly.

Delphi 2009 added an OwnsObjects property to TStringList (and an overloaded constructor).

--
Regards
Bruce McGee
Glooscap Software
0
Bruce
1/5/2009 5:35:28 PM
Reply:

Similar Artilces:

Delphi and Delphi for .Net
It seems that Delphi for .Net is slower than Delphi Win32 native applicaiton. I would like to know is it true all .Net application is slower than Win32 native applicaiton or it is Delphi for .Net only. Your information is great appreciated, Inung On 2011-06-21 18:20:17 +0100, Inung Huang said: > It seems that Delphi for .Net is slower than Delphi Win32 native applicaiton. > I would like to know is it true all .Net application is slower than > Win32 native applicaiton or it is Delphi for .Net only. If you are only running the code in the application once then, yes, yo...

Delphi XE memory leak?
Hi, I was browsing the net in search of DelphiXE reviews and features, when I found out [this| http://delphibugs.blogspot.com/2010/09/xe-new-bug-1-wild-memory-eating.html ] Can anyone confirm? I have not finished downloading the trial ISO yet (2 hours remaining <g>), but I will try to reproduce it myself when it's done. Cheers, G I didn't believe it would happen, but it did the same thing in my VM. I only even did it to say "doesn't happen here" because I find single purpose blogs like that astonishingly annoying. In any case, he's right. What&...

Delphi 2009 memory leak
I have a small app that uses dbExpress for MS SQL. I have the apps ReportMemoryLeaksOnShutdown set to true. Any time I use dbExpress to call a simple stored procedure (returns a single record with 2 fields) when I close the application memory leaks are reported. I am unable to determine if there is a known memory leak with the dbExpress driver. Can anyone help? This is driving me nuts. Here is the message text: --------------------------- Unexpected Memory Leak --------------------------- An unexpected memory leak has occurred. The unexpected small block leaks are: 21 - 28 b...

delphi 2010 memory not released when closing delphi project
each time im runing delphi 2010 the memory that was used was not release after closing a project and the memory don't stop to grow and the browsing for file becoming slow any idea ? Thanks Pierre Auger wrote: > each time im runing delphi 2010 the memory that was used was not > release after closing a project and the memory don't stop to grow and > the browsing for file becoming slow > > any idea ? You are using some 3rd-party components that do not properly release memory in their design-time packages would be my guess. A design-time package stays l...

Memory usage in Delphi 2007 vs. Delphi 5
Going from Delphi 5 to Delphi 2007 and finding something way unexpected. The reportedly *same code, and same data,* uses about 104 MB in Delphi 5 and about 400 MB in Delphi 2007 according to the Windows Task Manager. Now, I know that it is not the most accurate way of measuring memory usage, but it gives us an idea of the proportion of memory use in Delphi 2007. Before we go deeper, we just created 20,000 objects and added them to an object list in Delphi 5 and 2007. The result in memory use still looks like 50 MB (Delphi 5) to 178 MB (Delphi 2007). We've downloaded ...

Delphi 2009 HTTPRIO Memory Leak
After wrestling with issues about when to and when not to free HTTPRIO objects created in code, I still have one problem: With Delphi 2009 I have a routine that calls a SOAP function derived from a WDSL call that returns a TXMLData objects (actually it is just some XML, but that is what was created by the interface). The HTTPRIO object is created in code. I am explictly freeing the returned TXMLData, but there remains some memory leaks which I am having problems tracking down. Are there any known gotchas for using this or are there other references I have to explicitly free? ...

FastMM in Delphi 2010
Is there a way to get a memory leak report with FastMM either with the embeded version or the standalone that gives you the line number where the memory leak occur like Memcheck does. Thanks in advance. Ronaldo Santana wrote: > Is there a way to get a memory leak report with FastMM either with > the embeded version or the standalone that gives you the line number > where the memory leak occur like Memcheck does. > > Thanks in advance. I use this as default in my applications: ReportMemoryLeaksOnShutdown:= DebugHook <> 0; Cesar Romero Hi Cesar...

Delphi XE TSQLStoredProcedure Memory Leak
I am running into a memory leak when I am using a TSQLStoredProcedure created at run time with parameters. Here is code example that is creating the problem. {code} // Create the stored procedure. SQLStoredProcedureRecordEvent := TSQLStoredProc.Create(nil); // Set the parameters of the stored procedure. with SQLStoredProcedureRecordEvent do begin // Set the sql connection. SQLConnection := SendgridEventHandlerDM.DataModule_SendgridEventHandler. SQLConnection1; // Set the name of the procedure. StoredProcName := 'CreateBounceRecord'; ...

Delphi 2010 - dbexpress
Hi I use the dbx driver for firebird named dbxfb.dll and in my application i do a select every seconds. the memory of the process increase every 30 minutes but when i use Fastmm to check the memory leaks : no memory leak. I have noticed that if i do not do the open and close primitive, no more memory leak !! Here is my source LQuery := TSQLQuery.Create(Self); LQuery.SQLConnection := SQLConnection; LQuery.CommandText := 'SELECT * FROM '+ TableName + ' where EventId = :EventId'; try LQuery.ParamByName('EventId').AsInteger := EventId; LQuery.Open; LResult...

Where is the memory leak in this Delphi code? [Edit]
"Also, ask here if you don't know which group is best for your post" - moderator, please move this if you know of a better forum. Thanks! Can anyone help? I asked this on Stack Overflow and got it closed as "not a real question" (because "where is my memory leak" isn't a real question?). I have been searching for weeks and am desparate. I have thrown out 95+% of my code and still hit out of memory errors. Can soemone pelase help me? [Update: I may not have made it clear that the memory leak is in the server, not the client. Sorry] Here's ...

Delphi 2009 memory consumption (leak?)
Hi! I'm converting an old project of a couple of hundred files to Delphi 2009. In the process, I'm also changing the policy so, that instead of adding all my folders with code files to search path, I add the code files directly to the project and keep the search path empty (this among other things because at least in older Delphi's the length of the search path was limited and I started hitting the limit). At the same time I want to clean the project so, that I only add the files really needed, since my folde rs contain lots of legacy code files also that are no longer used. ...

Memory Leak, Leak, Leak, Leak.....
All, I have spent a lot of time watching the life being sucked out of my computer as I develop using PB during the day. I can document PB 7.0 8030 leaking memory every time I open and close the library, save an userobject, open a datawindow, etc. Some times the memory comes back when when I close PB, but mostly not. On one occasion I watched a nearly full restoration of available memory after closing Powerbuilder and then MSOutlook. How could MSOutlook release memory? Anyhows, I just had to vent. Is anyone else suffering the slow loss of memory? I don't see a lot of thr...

TDBChart and Delphi XE5 Update 2
Hi I've just converted a chart-heavy project from Delphi XE3 to Delphi XE5. I'm using the Standard TeeChart edition included with Delphi EurekaLog is now reporting memory leaks in VCLTee.DBChart where no leaks were reported in XE3 The leaks are still evident even with a new project and a single TDBChart with three bar series connected to a TADOdataset using the TeeChart designer in the IDE with no code. Is there anything I can do about this, given that I have no access to the source code? The EurekaLog report: |Methods |Details|Stack |Address |Module |Offset |...

Use of the build-in memory leak detector in Delphi 2010
Hello, I want to track the memory leaks in my application (I know there are some) but I can't find how to get the build-in memory leak detector to work. I've search on the net, on these forums and in the online help about this, but I couldn't find where in Delphi I should go to activate it. As no memory leaks are ever reported, even if I know there are some, I guess it's not activated. Thanks for your help. Am 23.06.2010 09:42, schrieb Yoann Coldefy: > I want to track the memory leaks in my application (I know there are some) but I can't find how to get the ...

Web resources about - Delphi VCL Memory Leak? - embarcadero.delphi.general

Delphi - Wikipedia, the free encyclopedia
... an archaeological site and a modern town in Greece on the south-western spur of Mount Parnassus in the valley of Phocis . The site of Delphi ...

Delphi Automotive (@DelphiAuto) on Twitter
Log in Sign up You are on Twitter Mobile because you are using an old version of Internet Explorer. Learn more here Delphi Automotive @ DelphiAuto ...

Delphi Connect for Verizon on the App Store on iTunes
Get Delphi Connect for Verizon on the App Store. See screenshots and ratings, and read customer reviews.


Audi working with Delphi to develop autonomous car tech
Audi is developing an iPad-sized device that will pack all the necessary computing power for a self-driving car

US approves China company's acquisition of Delphi biz
The Committee on Foreign Investment in the United States has formally approved the acquisition of Delphi's global production of braking systems ...

Verizon And Delphi Officially Launch Vehicle Diagnostics Service - $250 For The Module, $5 A Month On ...
If you're a car nut, a paranoid parent, or a small business owner looking to do a little, uh, company vehicle economy analysis, Verizon's teamed ...

Watch out Google: Delphi gives Ars a ride in its self-driving car
The automotive components maker gave Ars a preview ride around the neighborhood. MOUNTAIN VIEW, CA—On Thursday morning I met with Delphi at its ...

The skinny on Delphi's autonomous road trip across the United States
Filed under: Green , Videos , Autonomous Last week, Delphi's autonomous car became the first to complete a coast-to-coast trip across the United ...

Delphi partners with WiTricity on automated wireless charging system
One could easily argue that parking between the white lines at any local hangout presents a challenge for some inexperienced drivers. So, why ...

Resources last updated: 12/15/2015 8:55:30 PM