Fix leak detector on HeadlessAppContext (#51442)

Conrad Irwin created

Closes #ISSUE

Before you mark this PR as ready for review, make sure that you have:
- [ ] Added a solid test coverage and/or screenshots from doing manual
testing
- [ ] Done a self-review taking into account security and performance
aspects
- [ ] Aligned any UI changes with the [UI
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)

Release Notes:

- N/A

Change summary

crates/gpui/src/app/headless_app_context.rs | 8 ++++++++
1 file changed, 8 insertions(+)

Detailed changes

crates/gpui/src/app/headless_app_context.rs 🔗

@@ -186,6 +186,14 @@ impl HeadlessAppContext {
     }
 }
 
+impl Drop for HeadlessAppContext {
+    fn drop(&mut self) {
+        // Shut down the app so windows are closed and entity handles are
+        // released before the LeakDetector runs.
+        self.app.borrow_mut().shutdown();
+    }
+}
+
 impl AppContext for HeadlessAppContext {
     fn new<T: 'static>(&mut self, build_entity: impl FnOnce(&mut Context<T>) -> T) -> Entity<T> {
         let mut app = self.app.borrow_mut();