gemini-cli - ✅(Solved) Fix OOming with memory option set in /settings [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
google-gemini/gemini-cli#24924Fetched 2026-04-09 08:17:22
View on GitHub
Comments
1
Participants
2
Timeline
12
Reactions
0
Assignees
Timeline (top)
labeled ×4unlabeled ×2added_to_project_v2 ×1assigned ×1

PR fix notes

PR #25049: fix: resolve lifecycle memory leaks by cleaning up listeners and root closures

Description (problem / solution / changelog)

Summary

This PR addresses multiple severe memory leaks that cause the CLI's memory usage to continually grow over long sessions, leading to terminal backbuffer retention and massive React Fiber tree bloat.

Details

  1. TerminalBuffer & Render Teardown Leaks (cleanupFunctions): registerCleanup was being used in both interactiveCli.tsx and AppContainer.tsx to register instance.unmount() and background task termination logic. Because the application was missing a corresponding removeCleanup hook, these closures (and by extension the entire rootUiRef and internalOnBeforeRender functions from Ink) were retained indefinitely in the global array. A new removeCleanup utility function has been added to packages/cli/src/utils/cleanup.ts and called in the appropriate finally and React lifecycle cleanup stages to prevent this unbounded growth.
  2. Fuzzy Finder Status Listener Leaks (statusChangeListeners): The statusChangeListeners in packages/core/src/tools/mcp-client.ts was implemented using a simple array. During rapid mounting/unmounting of the fuzzy finder dialog, failure to correctly find and slice listeners could cause duplicate retention. It has been converted to a Set<StatusChangeListener> which intrinsically enforces uniqueness and guards against these leaks.

Related Issues

Fixes #24924

How to Validate

Run preflgiht

Pre-Merge Checklist

<!-- Check all that apply before requesting review or merging. -->
  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

Changed files

  • packages/cli/src/gemini.test.tsx (modified, +2/-1)
  • packages/cli/src/gemini_cleanup.test.tsx (modified, +2/-0)
  • packages/cli/src/interactiveCli.tsx (modified, +50/-8)
  • packages/cli/src/ui/AppContainer.tsx (modified, +15/-3)
  • packages/cli/src/utils/cleanup.ts (modified, +14/-0)
  • packages/core/src/services/shellExecutionService.test.ts (modified, +7/-0)
  • packages/core/src/services/shellExecutionService.ts (modified, +16/-1)
  • packages/core/src/tools/mcp-client.ts (modified, +3/-6)

Code Example

> /about
# paste output here
RAW_BUFFERClick to expand / collapse

What happened?

Reported hitting an Out-of-Memory (OOM) crash at approximately 1.5-1.6 GB, with the memory setting option in /settings proving ineffective.

See the Internal Gemini CLI Issues list.

What did you expect to happen?

Not to OOM

Client information

<details> <summary>Client Information</summary>

Run gemini to enter the interactive CLI, then run the /about command.

> /about
# paste output here
</details>

Login information

No response

Anything else we need to know?

No response

extent analysis

TL;DR

Adjusting the memory setting option in the /settings menu may not be effective, so exploring alternative methods to manage memory usage is necessary.

Guidance

  • Investigate the Internal Gemini CLI Issues list for known problems related to memory management and OOM crashes.
  • Run the /about command in the Gemini CLI to gather client information, which may provide clues about the system's configuration and potential memory constraints.
  • Consider monitoring system resources and memory usage patterns to identify potential leaks or inefficiencies contributing to the OOM crashes.
  • Review the Gemini CLI documentation for any recommendations on optimizing memory usage or configuring the application for low-memory environments.

Notes

The provided information lacks specific details about the system, configuration, or usage patterns, making it challenging to provide a targeted solution. Further investigation into the Internal Gemini CLI Issues list and client information may be necessary to identify the root cause.

Recommendation

Apply workaround: Given the ineffective memory setting option, exploring alternative methods to manage memory usage, such as optimizing system resources or configuring the application for low-memory environments, may be necessary to mitigate the OOM crashes.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING