Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi: How can I debug access violations when closing my application?

I'm using Delphi 6 and I've got an application which when being shut down produces access violation errors. We use EurekaLog so I'm getting stack traces for debugging, but the errors seem to occur randomly in a different unit each time, but always when something is being freed in the finalization section.

How can I go about debugging this to see what's causing the problem? I'm not sure how to start debugging things that happen when the application is being finalised.

[Edit:] Sorry if I was unclear, perhaps a better question would be: What's the best place to start debugging with breakpoints if I only want to walk through the finalisation sections? The errors seem to arise in third party components we use (the devexpress dx/cxgrid library) so I'd like to start debugging in my code at pretty much the last point before Delphi will start calling finalise routines in other units.

like image 223
Kieran Avatar asked Oct 10 '11 16:10

Kieran


1 Answers

This isn't much to go on, but if I had to guess, based on past experience... are you using packages or COM libraries? If you've got a global variable that's an interface, or an object whose class is declared in a BPL, and you unload the DLL/BPL before cleaning up the object/interface, you'll get access violations because your code is trying to do a VMT lookup in address space that is no longer mapped into the application.

Check for that and make sure you clean up all such variables before finalization begins.

like image 56
Mason Wheeler Avatar answered Nov 18 '22 22:11

Mason Wheeler