Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-09

Application slow shutting down

13 messages · 7 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Susie Nicol

Hi

I have an application with a main form, and several others whuich are only ever used in modal form.

The application is slow to terminate, and I cannot see why. The shutdown procedure, simplified a little looks like this: (datamodified a global Boolean; savedata another procedure in the same unit; the SQLcomponents are in a a data module)

procedure FinishUp;
begin
  if datamodified then
    savedata;
 sqltransaction1.commit;
 sqlconnection.close(True);

Application.Terminate {line A}

end;

The debugger shows me that everything is fine until line A, when the program hangs: often for 15 seconds, sometimes for ever.

XFCE on Linux complains that the window containing the main form cannot be closed because 'the application may be busy'.

I have tried to replace line A with 'halt' or 'close' without any difference. The connection to the database is indeed closed.

I am using Lazarus 1.4.2, 64-bit, Linux XFCE desktop, GTK+2 widget set.

Any suggestions about where to look next will be very welcome. -------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150930/0549f749/attachment.html>

Reply by email

Michael Van Canneyt
to Susie Nicol
Susie Nicol wrote 31 lines
Hi I have an application with a main form, and several others whuich are only ever used in modal form. The application is slow to terminate, and I cannot see why. The shutdown procedure, simplified a little looks like this: (datamodified a global Boolean; savedata another procedure in the same unit; the SQLcomponents are in a a data module) procedure FinishUp; begin if datamodified then savedata; sqltransaction1.commit; sqlconnection.close(True); Application.Terminate {line A} end; The debugger shows me that everything is fine until line A, when the program hangs: often for 15 seconds, sometimes for ever. XFCE on Linux complains that the window containing the main form cannot be closed because 'the application may be busy'. I have tried to replace line A with 'halt' or 'close' without any difference. The connection to the database is indeed closed.

1. Are you using threads ?
2. Do you create a lot of components dynamically that are freed in the destructor of the form ?

Both can cause significant delays.

I am using Lazarus 1.4.2, 64-bit, Linux XFCE desktop, GTK+2 widget set. Any suggestions about where to look next will be very welcome.

What I usually do in such case is not use the debugger, but check using the strace command-line utility if there is still some activity in the application:

Put a writeln('something') before and after the Application.Terminate, and check what happens between the write() commands in strace's output.

Michael.

Reply by email

Gordon Cooper
to Michael Van Canneyt
Show quoted text 40 lines
On Wed, 30 Sep 2015, Susie Nicol wrote: > Hi > > I have an application with a main form, and several others whuich are > only > ever used in modal form. > > The application is slow to terminate, and I cannot see why. The > shutdown > procedure, simplified a little looks like this: (datamodified a global > Boolean; savedata another procedure in the same unit; the > SQLcomponents are > in a a data module) > > procedure FinishUp; > > begin > if datamodified then > savedata; > > sqltransaction1.commit; > sqlconnection.close(True); > > Application.Terminate {line A} > > end; > > The debugger shows me that everything is fine until line A, when the > program hangs: often for 15 seconds, sometimes for ever. > > XFCE on Linux complains that the window containing the main form > cannot be > closed because 'the application may be busy'. > > I have tried to replace line A with 'halt' or 'close' without any > difference. The connection to the database is indeed closed. Susie,

You said Linux with xcfe, but which version of LInux? Some of them
behave quite differently from others.

Gordon.

> _______________________________________________ > Lazarus mailing list > > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Susie Nicol
to Gordon Cooper
Gordon Cooper wrote 48 lines
> On Wed, 30 Sep 2015, Susie Nicol wrote: > > Hi >> >> I have an application with a main form, and several others whuich are >> only >> ever used in modal form. >> >> The application is slow to terminate, and I cannot see why. The shutdown >> procedure, simplified a little looks like this: (datamodified a global >> Boolean; savedata another procedure in the same unit; the SQLcomponents >> are >> in a a data module) >> >> procedure FinishUp; >> >> begin >> if datamodified then >> savedata; >> >> sqltransaction1.commit; >> sqlconnection.close(True); >> >> Application.Terminate {line A} >> >> end; >> >> The debugger shows me that everything is fine until line A, when the >> program hangs: often for 15 seconds, sometimes for ever. >> >> XFCE on Linux complains that the window containing the main form cannot >> be >> closed because 'the application may be busy'. >> >> I have tried to replace line A with 'halt' or 'close' without any >> difference. The connection to the database is indeed closed. >> > > Susie, > You said Linux with xcfe, but which version of LInux? Some of them behave quite differently from others. Gordon.

Hi Gordon - thanks for replying

OpenSuse, 13.2, with XFCE 4.10

Susie
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150930/a4196f56/attachment.html>

Reply by email

Susie Nicol
to Michael Van Canneyt: 1. Are you using threads ? 2. Do you create a lot of components dynamically that are…

On Wed, Sep 30, 2015 at 7:50 PM, Michael Van Canneyt <

Show quoted text 18 lines
wrote: On Wed, 30 Sep 2015, Susie Nicol wrote: Hi > > I have an application with a main form, and several others whuich are only > ever used in modal form. > > The application is slow to terminate, and I cannot see why. > XFCE on Linux complains that the window containing the main form cannot be > closed because 'the application may be busy'. > > 1. Are you using threads ?

Hi Michael.

I'm not using threads.

Show quoted text 5 lines
2. Do you create a lot of components dynamically that are freed in the destructor of the form ? Both can cause significant delays.

Very few overall, and I thought they were safely freed. But heaprtc shows 66 unfreed memory blocks, so that is something I shall check tomorrow (it's late in NZ)

Show quoted text 12 lines
> I am using Lazarus 1.4.2, 64-bit, Linux XFCE desktop, GTK+2 widget set. > > Any suggestions about where to look next will be very welcome. > What I usually do in such case is not use the debugger, but check using the strace command-line utility if there is still some activity in the application: Put a writeln('something') before and after the Application.Terminate, and check what happens between the write() commands in strace's output.

Thanks for that ingenious suggestion. A quick check shows nothing happens between the two write()s, so Application.Terminate is returning immediately. There follows 96 thousand lines of output before the program gets SIGKILL, so I guess that it was pretty busy!

Something for me to get my teeth
Susie
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150930/db567d2f/attachment-0001.html>

Reply by email

Patrick Chevalley
Very few overall, and I thought they were safely freed. But heaprtc shows 66 unfreed memory blocks, so that is something I shall check tomorrow (it's late in NZ)

?
Resolve this errors and then try without heaptrc, it is expected that memory analysis take at lot of time when the program exit.

Patrick

Reply by email

Graeme Geldenhuys
to Patrick Chevalley

Hello Patrick,

Patrick Chevalley wrote
Resolve this errors and then try without heaptrc, it is expected that memory analysis take at lot of time when the program exit.

TIP:
Also develop your programs with -gh -gl (memory leak detection) enabled, and show console output. It is MUCH easier to fix a memory leak the minute you introduced it, compared to months down the line when you have stacks of memory leaks.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email

Patrick Chevalley

Hi Graeme,

TIP: Also develop your programs with -gh -gl (memory leak detection)

I agree and always use heaptrc for my development projects.

My suggestion to try without heaptrc is only to check if this is the reason for "slow shutting down". In this case the problem is solved because a release build without this option will not be affected.

Patrick

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150930/79d0cf42/attachment.html>

Reply by email

Graeme Geldenhuys
to Patrick Chevalley

Hello Patrick,

Patrick Chevalley wrote
My suggestion to try without heaptrc is only to check if this is the reason for "slow shutting down". In this case the problem is solved because a release build without this option will not be affected.

Run your program from the command line, and don't compile it with -WG (ie: tell the compiler it is a console program, not a GUI one - if you are using Windows).

If it takes so long to shut down, that means you have a heck of a lot of memory leaks. As you can guess, that is bad and should always be fix! Simply disabling heaptrc is not really a solution.

But yes I fully understand "releas builds" of your application shouldn't include heaptrc. But memory leaks should be fixed none the less.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email

Gordon Findlay
to Graeme Geldenhuys

Thanks all.

Once I tracked down the two components that had not been freed, the hanging stopped.

Some create tips in this thread. Thansk for all of them.

On Thu, Oct 1, 2015 at 6:31 AM, Graeme Geldenhuys <

Show quoted text 40 lines
wrote: Hello Patrick, On 2015-09-30 at 17:56, Patrick Chevalley wrote: > My suggestion to try without heaptrc is only to check if this is the > reason for "slow shutting down". In this case the problem is solved > because a release build without this option will not be affected. Run your program from the command line, and don't compile it with -WG (ie: tell the compiler it is a console program, not a GUI one - if you are using Windows). If it takes so long to shut down, that means you have a heck of a lot of memory leaks. As you can guess, that is bad and should always be fix! Simply disabling heaptrc is not really a solution. But yes I fully understand "releas builds" of your application shouldn't include heaptrc. But memory leaks should be fixed none the less. Regards, - Graeme - fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20151001/1a92515e/attachment.html>

Reply by email

Susie Nicol
to Gordon Findlay

Sorry all: that last reply was from me (the OP).

I was on my friend's machine, and he is also on the list. Confusion is universal.

Susie

Gordon Findlay wrote 58 lines
Thanks all. Once I tracked down the two components that had not been freed, the hanging stopped. Some create tips in this thread. Thansk for all of them. On Thu, Oct 1, 2015 at 6:31 AM, Graeme Geldenhuys < > wrote: > Hello Patrick, > > On 2015-09-30 at 17:56, Patrick Chevalley wrote: > > My suggestion to try without heaptrc is only to check if this is the > > reason for "slow shutting down". In this case the problem is solved > > because a release build without this option will not be affected. > > > Run your program from the command line, and don't compile it with -WG > (ie: tell the compiler it is a console program, not a GUI one - if you > are using Windows). > > If it takes so long to shut down, that means you have a heck of a lot > of memory leaks. As you can guess, that is bad and should always be > fix! Simply disabling heaptrc is not really a solution. > > > But yes I fully understand "releas builds" of your application > shouldn't include heaptrc. But memory leaks should be fixed none the > less. > > > > Regards, > - Graeme - > > fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal > http://fpgui.sourceforge.net/ > > My public PGP key: http://tinyurl.com/graeme-pgp > > > -- > _______________________________________________ > Lazarus mailing list > > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus > -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20151001/79000cff/attachment-0001.html>

Reply by email