Crash on application close - in Destroy of TCustomTimer or THintWindow lazarus / 21-General ---------------------------------------------------------------------- rborsey · 2025-02-02 14:24 Hi all. I've got a problem on closedown of my (rather large - about 90k lines of code) form-based application. It has only appeared recently and happens maybe once every 20 times I run the app so maybe some sort of race condition during the shutdown. Anyway I catch the error and dump the back trace and it appears to be when the application destroys all its components (presumably during its own destruction) and it seems to happen on trying to destroy either a CustomTimer (which I don't directly use) or HintWindow (I do use hints). I have written out all the application.components and immediately after startup I get a list of all the forms created in my application. If I run this dump very shortly after statup (with my first form action) then a TCustomTimer has been added to the list (no idea what has created that). If I pass over a control with a hint then the THindWindow is created too. I don't get an AV error report or invalid memory access - typically the application hangs and then I either get a heaptrace (showing a zillion blocks lost) or a windows style Searching for a Solution bow . . . Anybody have an idea what might be going on? Where to start looking? Thanks Richard ---------------------------------------------------------------------- Thaddy · 2025-02-02 14:34 Kill the timer(s) in form.onclosequery and only then give permission to close the app. ---------------------------------------------------------------------- rborsey · 2025-02-02 23:17 Hi Thaddy. Yes I would do that (I free loads of stuff and close down threads etc in CloseQuery and/or Clos. The problem os that it is not my code which creates the CustomTimer - not directly at least. It seems to appear spontaneously. I use timers from mmsystem (which I do stop). ---------------------------------------------------------------------- rborsey · 2025-02-03 17:33 Aha. Solved Thank-you Thaddy - your reference to onclosequery made me think. I had been using closequery to decide if it was fine to close - saves done, nothing critical underway, and using onclose to stop threads and free resources. The documentation (what I found anyway) isn't super clear on when to do this latter set of tasks an d so on reflectionI thought maybe I was shutting things down too late and thus maybe creating some race conditions between internal cleanup and the application itself closing down. I moved all the thread termination and freeing actions to onclosequery and Bingo - everything works fine. Job done . . .