GPF on exit is usually caused by wrong deinitialization sequence. For example, the following could have happened: some code that releases all objects has been called already and now you have a dangling pointer and the code currently executing is trying to release the same object. Since the object is no longer there you get a GPF.
Such situations are usually hard to debug. What you need is a dedicated deinitialization where you would disconnect, finalize, flush, close, etc. all objects that you initialized while running the program. In most cases all you need is to just set the pointet to the object to Nothing
- built-in resource management will have the object properly deinitialized. You have to execute this code before the whole program termination starts - somewhere like when closing the main window.