# Fix text finder crash from unbounded memory use \(\#60377\) · gitcafe/zed

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

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

Visibility: public

Requested revision: e58a02d97409c2ecdbeaee7a936131ccc8f9dc16

Requested commit: e58a02d97409c2ecdbeaee7a936131ccc8f9dc16

Commit: e58a02d97409c2ecdbeaee7a936131ccc8f9dc16

Tree: 17254958f1c450b9d63dd02d508452040ccd3af3

Author: David Alecrim

Committer: GitHub

## Message

```
Fix text finder crash from unbounded memory use (#60377)

- Fixes #60238.
- The text finder could spike memory into the tens of gigabytes and
crash the app. The finder was copying the full matched line into every
match it kept, so memory grew with the number of matches times the size
of each line. Enough matches carrying enough text and the process runs
out of memory.

## Solution

- Stop storing line text on matches. Each match now keeps only its
position and column, and the text shown in a row is built lazily for the
visible rows, using a bounded slice around the match rather than the
whole line. Line boundaries come from the buffer's line index instead of
re-scanning the content per match.
- Cap the number of matches the finder builds while streaming results,
using the same ceiling project search already applies. This keeps the
finder from ever assembling an unbounded match list on the UI thread.
- Behavior is unchanged: every occurrence is still its own row, jumping
to a match lands on the exact line and column, and the rendered text and
highlighting look the same. The finder just no longer holds text
proportional to the match count.

## Testing
- Added tests covering the new behavior: the match count is capped while
streaming, every occurrence below the ceiling still becomes its own
match at the correct line and column, and the rendered slice around a
match stays bounded on a huge line while still covering a whole short
line.
- Verified by hand with the reproduction from the issue. The screenshot
below shows the memory usage and the matching against the issue data:
<img width="1277" height="1053" alt="Screenshot 2026-07-03 at 17 43 11"
src="https://github.com/user-attachments/assets/71c0aa3b-2423-427d-91ba-792951d9ba31"
/>

## 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)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

---

Release Notes:

- Fixed a crash and high memory usage in the text finder.
```

## Parents

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

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