# gpui: Fix \`start_display_link\` leading to resource leak on hidden windows \(\#11289\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/4024b9ac4d6382c5fb4b1179be3c79206de6c307)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 4024b9ac4d6382c5fb4b1179be3c79206de6c307

Requested commit: 4024b9ac4d6382c5fb4b1179be3c79206de6c307

Commit: 4024b9ac4d6382c5fb4b1179be3c79206de6c307

Tree: a94649e1657b7479daea1f1596419a4093eb7c6d

Author: Matthias Grandl

Committer: GitHub

## Message

````
gpui: Fix `start_display_link` leading to resource leak on hidden windows (#11289)

Release Notes:

- N/A

While developing [Loungy](https://loungy.app), I noticed that everytime
I wake my laptop, Loungy starts consuming 100% CPU. I traced it down to
`start_display_link` as there was this error message at the time of wake
up:

```
[2024-05-02T05:02:31Z ERROR util] /Users/matthias/zed/crates/gpui/src/platform/mac/window.rs:420: could not create display link, code: -6661
```

The timeline is this:

1. The application is hidden with `cx.hide()`
2. The system is put to sleep and later woken up
3. `window_did_change_screen` would trigger immediately after wakeup,
calling `start_display_link`
4. `start_display_link` fails catastrophically as `DisplayLink::new`
starts hogging all the CPU for some reason?
5. throws the error message above
6. Once the window is opened, `window_did_change_occlusion_state` it
retriggers `start_display_link` and the CPU issue subsides
````

## Parents

- [b523ee6980c97bf6c1002610514bf8fd4e41b0dd](https://git.cafe/gitcafe/zed/commit/b523ee6980c97bf6c1002610514bf8fd4e41b0dd?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/4024b9ac4d6382c5fb4b1179be3c79206de6c307?format=markdown)
