SetLength(Copier,0);
Copier := nil;
This is interesting... Why you do this? If Copier is local variable, it will be freed when you leave the procedure/function.
Main Topics
Browse All TopicsI'm working on upgrading an old program for an old employer of mine. The project produces Postscript based on input files (layout files and data files, producing printer-ready ID cards). The original project was in Delphi 1.0 and Visual C++ 1.5; later on I wrote a Delphi component which does the Postscript generation in Delphi 5, and this was used in subsequent projects.
Now I have been called back to rewrite the front end, using Delphi 5 and the Delphi 5 component (with some minor additions to support Unicode). During testing, some major memory leaks were found, which apparently have always been there, but never been noticed before. The new card layout, which uses lots of graphics, has exacerbated the problem.
I downloaded AQTime (http://www.automatedqa.co
Fpage.FActualPostscriptDat
Fpage.FActualPostscriptDat
TTF.ProducePostscript;
TTF is a method which generates and returns a very large string (it can be several hundred K), and the stringlist Fpage.FActualPostscriptDat
I have tried to move the concatenation to local strings, and made the method function returning a string to a method procedure operating on a string which belonged to the object:
TTF.ProducePostscript;
helper := Fpage.FActualPostscriptDat
helper1 := TTF.ProducedPostscript;
Fpage.FActualPostscriptDat
Here, too the leak occurred on the concatenation. I tried concat(helper, helper1). No good. I tried delete and insert.
TTF.ProducePostscript;
helper := Fpage.FActualPostscriptDat
helper1 := TTF.ProducedPostscript;
Fpage.FActualPostscriptDat
Fpage.FActualPostscriptDat
Didn't help. Tried using a dynamic array to avoid the concatenation:
var
copier : array of char; (this is local to the procedure doing this)
...
SetLength(Copier,
Length(Fpage.FActualPostsc
+ Length(TTF.ProducedPostscr
Move(Fpage.FActualPostscri
Length(Fpage.FActualPostsc
Move(TTF.ProducedPostscrip
Copier[Length(FPage.FActua
Length(TTF.ProducedPostscr
SetLength(helper,Length(Co
Move(Copier[0],helper[1],L
SetLength(Copier,0);
Copier := nil;
FPage.FActualPostscriptDat
helper := '';
Now AQTime shows the memory of the first SetLength(Copier, etc.) as unreleased, despite the SetLength(Copier,0) and Copier := nil. It's actually worse than the string version.
I am at a loss here - what could cause these leaks?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi,
I hardly believe that concat can do such a things.
Could You try not to use TTF.ProducePostscript;
Does something like this also causes leaks?
For me, using D7, it's ok.
Fpage.FActualPostscriptDat
Fpage.FActualPostscriptDat
stringOfChar('b',120000);
Comments on the comments:
1. I'll download memchk today and try it later, see what it can do.
2. Why SetLength(Copier,0);
Copier := nil;
Because of the strange leaks showing up in strange places, I did a lot of testing with a lot of overkill for removing them.
3. TTF.ProducePostscript - That's what I've been looking at since I wrote the request here. I'm guessing that somewhere there there's some bizarre memory overwrite which is confusing the memory manager farther down the road. I'll replace the call to it with instead filling in a large buffer of data, and see if it helps.
4. Fpage.FActualPostscriptDat
That's it for now...I'll be in later tonight - today have to work on other things.
It took me a while to get Memcheck to work, after I did, it is not reporting ANY of the leaks - it reports exactly one leak, which occurs 5 times, and each eats 28 bytes - it seems that the JVOutlookBarButtonActionLi
I wish it were right - however, when I run Process Explorer and run my program, every time I create a page of Postscript, my "Private Bytes" uses increases by another 130K
I am also having some problems with AQTime's reporting. One of the leaks that it found was a leak in Strings.SaveToFile - the bug is in Classes.pas, and is documented here:
http://www.kyler.com/conte
I fixed this, and that leak went away. Now I am running AQTime with the modified code, and it is again finding the old leak in classes - but when tracing the code through the debugger, I can see that it is using the modified classes.pas, and that the memory is being released.
> I wish it were right - however, when I run Process Explorer and run my program, every time I create a page of Postscript, my "Private Bytes" uses increases by another 130K
Even if your program is OK (without taking the smaller leaks into account) and everything is deallocated properly, it may be the ***Delphi memory manager*** who asks Windows for more RAM instead of reusing the already allocated memory. This may be due to performance reasons and it's not necessarily a bad thing.
Try to generate 100 postscript pages:
for i := 1 to 100 do
begin
CreatePage;
FreePage;
end;
and see if "Private Bytes" report 100*130K.
Business Accounts
Answer for Membership
by: Ivanov_GPosted on 2007-01-14 at 14:12:15ID: 18313001
I don't know about AutomatedQA. I had bad experience with it. Later I moved to MemCheck - http://v.mahon.free.fr/pro /freeware/ memcheck/ . A simple unit which acts as a Memory Manager and blow an exception whenever you make a leak. Just add the unit and MemChk; like. When a memory is not freed, it will throw an exception. Try with it, maybe it will give you some more information to identify the leak.