# Fix project search holding a reference to closed unsaved files \(\#61677\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 7ecab315fbe795ca164d45747dbe88d95da5eeb0

Requested commit: 7ecab315fbe795ca164d45747dbe88d95da5eeb0

Commit: 7ecab315fbe795ca164d45747dbe88d95da5eeb0

Tree: 283e05f02e71266213eb09e205d5b9838b4ca3d1

Author: Pingy

Committer: GitHub

## Message

```
Fix project search holding a reference to closed unsaved files (#61677)

# Objective

Fixes #28398

## Solution

This issue was occurring because `ProjectSearch` stored
`Entity<MultiBuffer>` with has reference counted pointers to underlying
buffers
The function `remove_deleted_buffers` is renamed to
`remove_stale_buffers` and it now also checks for buffers which do not
have a file associated with them and are closed. Then, it removes them
from `Entity<MultiBuffer>` stored in ProjectSearch. This function is
also called in again when workspace is upgraded.

## Testing

Bug being fixed was manually verified. 

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [ ] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable


Release Notes:

- Fixed project search retaining results from closed untitled buffers.

---------

Co-authored-by: Kirill Bulatov <kirill@zed.dev>
Co-authored-by: zed-zippy[bot] <234243425+zed-zippy[bot]@users.noreply.github.com>
```

## Parents

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

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