Delphi 7 debugger hangs briefly on application exit


I use Delphi 7. On occasion, when I am running an application in the debugger and I exit the application normally, Delphi seems to get hung, and hangs the rest of my computer desktop as well. This always remedies itself after some period of time. Sometimes it takes a few seconds, sometimes as much as a minute, and sometimes not at all  all within the same application. It only happens when debugging, the applications all run fine outside of the debugger. This only happens when I terminate the application normally  if I do a Program Reset I return to the debugger with no delay.

I have never been able to tell what is going on when this happens. Ive tried watching task manger when it occurs but even the task manager is not updating its screen when this goes on. I suspect its bad behavior on the part of some component that I am using because it does not happen with simple programs, only my more involved projects.

Has anyone else experienced this? Any Ideas?

LVL 14
Who is Participating?
2266180Connect With a Mentor Commented:
>> It is not integrated with the debug environment.
it doesn't have to be. these components usually detect if the debugger is running or not.

in any case, first place to look at, are the finalization sections of the units.

if nothing comes up after a quick view, I would do somethign like the following to detect where the "freeze" occures:
- use a logging system
- log a line right after in the dpr file
- log a line in the destructor of the main form as well
- create 2 units, named blabla1 and blabla2 (name it to whatever you like), and in the finalization section add a log line in both
- logging usefull information is a must (like: now executing finalization section of unit blabla1, or destructor of main form, etc)
- the logger must be able to also log the time of the call so that you know when the message was logged

now, with this prepared (it should really only take a few minutes to setup everything, provided you have a logging system with the minimum characteristics mentioned above).

now, step 2:
- place the unit blabla1 as the first unit in the dpr, BUT, without messing up whatever other units MUST be first (like madexcept, fastmm, etc. probably your AQTime also has a unit there first). this blabla1 will come the first after all the others
- place the unit blabla2, as the last unit in the dpr.

and now, I think you know what comes :) trial and "error" of the "divide et impera".
looking in the logs, you will notice where the "freeze" is happening. if you're lucky, you find it fast from the first call as belonging to either the first units from the dpr, or to some code after the main form destruction and project finalization.
if not, then you will notice the freeze to be between blabla1 and blabla2. so, move blabla1 down some units (preferably half). is it still between blabal1 and blabla2? if yes, again move it down, if not, move it back to first and move blabla2 in it's place. repeat.
eventually, you will end up with who is making the freeze.

it's ugly, but I don't know of any automated tool to trace the execution time of calls.
are you using memcheck/fastmm with some debugging configured/etc? these kind of componetns will usually compute some information related to memory usage, but you should get some a message saying so because usually there is always something that is "left unreleased".

other then that, I am afraid you will have to provide us with the list of 3rd party components you are using in your project.
SteveBayAuthor Commented:
I use AQTime for profiling and memory leak detection. It is not integrated with the debug environment.

The 3rd party component list is long and varied. So I looked for the lightest application I could find that has exhibited this behavior.

This particular application is a DLL that reads data from an XML and updates Data in a MSSQL database. Its 3rd party components are limited to the following:

Raize Components (Ive use them in just about every thing for many years. I highly doubt that these are the problem).

There are also a number of CodeSite calls (also from Raize).
This could be a suspect because it sends windows messages and could be sending millions upon exit. I have made efforts to disable all CodeSite calls and have still seen the behavior. This also would not explain why it only happens in the debugger as CodeSite works the same with or without the debugger. And once again, I've been using it for many years in lots of stuff and this issue has only come up recently, the last 6-8 months or so. I've also search Raize news groups for similar reports and found none. Still, I am not ready to completely rule this one out.

TLbBlowFish  - formerly from TurboPower now open source from Source Forge;

NativeXML - from Theres not enough going on in this component to warrant unexpected behavior.

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

SteveBayAuthor Commented:
Good stuff ciuly...:)

CodeSite is my logging util. I put a call in the dpr right after the Run. and I put one in the Mainform destructor. Both of those were called before the hang occured.

BTW I ran the program 5 times and it only causes a hang once about 30 seconds.

I don't know what you are refering to by "finalization section of unit". Is that the form destructor?
2266180Connect With a Mentor Commented:
no. in a unit you have a several sections:


the most used are the first 2. but there are cases when the otehr 2 are used as well. so some of you runits will have them some not.

see below example of blabal1.pas
unit blabla1;
// nothing

Open in new window

SteveBayAuthor Commented:
You know, sometimes all a guy has to do is hit F1 and type a word (in this case "finalization") and a whole world of knowledge come pouring out:)

So I've done all of that and I will watch for the results.

In the mean time, just for grins, I when into Project->Options->Compiler and disabled everything in the Debugging section. The hang went away. (keep in mind it was only happing about 1 in 5 runs to begin with). I re-enabled every thing in the Debugging section, and the hang stayed away. I have not been able to reproduce the hang at all now. after several dozen runs - no hang.

Your help has been quite valuable.  Thank You

now there is a weird thing to keep in mind :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.