Delphi 7 debugger hangs briefly on application exit

Posted on 2007-12-05
Last Modified: 2013-11-23

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?

Question by:SteveBay
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 28

Expert Comment

ID: 20414630
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.
LVL 14

Author Comment

ID: 20415181
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.

LVL 28

Accepted Solution

2266180 earned 500 total points
ID: 20415382
>> 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.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 14

Author Comment

ID: 20415651
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?
LVL 28

Assisted Solution

2266180 earned 500 total points
ID: 20415918
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

LVL 14

Author Comment

ID: 20416040
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

LVL 28

Expert Comment

ID: 20416153
now there is a weird thing to keep in mind :)

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question