Fix bug 4167. Fire unload event before all data is gone to allow action during event handlers. r:travis