I've been wondering this since the beginning of .NET.

In WinForms, you are able to capture the "Form Closing" event of a form. This is invaluable to me, since it gives me a chance to perform "cleanup" (clearing objects, variables, etc.) before the application is terminated.

One thing I always wanted was a way to capture the "Window Closing" or, in the case of multi-tabbed browsers, "Tab Closing" event of a browser window.

Is there currently an industry-accepted method of doing this? There has to be a way, IMO, since secure websites destroy your session once you close the window (so some nosy person can't go through your browser history and see your bank account details).