AI Web App Memory Leak: Diagnosing 8 GB Single-Tab Usage and Fixes

    A mainstream AI chat web app was reported to consume up to 8.4 GB in a single browser tab, with memory growing over time rather than with conversation content. This article reviews the incident, explains why time-based growth is a key leak signal, outlines a systematic browser debugging workflow, and summarizes memory optimization practices for long-lived AI chat interfaces with streaming responses, rich text, and file uploads.

    Incident Review: One Tab Consumes 8 GB of Memory

    Recently, reports of abnormal memory usage in a mainstream AI chat product’s web version caught the attention of the developer community. According to user feedback, when the web app runs in a browser, memory usage in a single tab keeps climbing: some users shared screenshots showing more than 5 GB, others reported 6.4 GB, and the peak reached 8.4 GB. The result was obvious system lag and fans running at full speed.

    This was not an isolated occurrence. Similar complaints had persisted for more than a year. More than a year earlier, users had already posted screenshots showing a single tab using 3.6 GB of memory. More tellingly, users observed a pattern: memory usage seemed positively correlated with how long the page had been open, rather than simply with the amount of conversation content. One user described a session with only five messages and one PDF file. The page initially used about 250 MB, and after 15 minutes it had risen to 900 MB. This “linear growth over time” pattern is a typical characteristic of a memory leak.

    Eventually, the official support channel confirmed that the issue had been fixed and asked users who still encountered abnormal memory usage to continue providing feedback. However, the official channel did not explain what exactly was fixed or provide before-and-after memory comparison data.

    Why “Growth Over Time” Is the Key Clue

    For developers with frontend performance optimization experience, the phenomenon of “memory growing over time rather than with content” almost immediately narrows the investigation to the following categories:

    1. Timers and event listeners not cleaned up. The page may contain polling logic, such as checking session status or fetching asynchronous task results, WebSocket heartbeats, and global event listeners such as visibilitychange and resize. If these listeners are not properly removed when components unmount or sessions switch, they accumulate over time.

    2. Streaming response buffers not released. AI chat products commonly use streaming output, such as SSE or chunked transfer, to render answers token by token. If the implementation appends a reference for every chunk without releasing it in time, or if the Reader does not call cancel or close when the stream ends, the underlying buffer remains alive.

    3. Unbounded DOM node growth. In long conversations, if all historical messages remain in the DOM without virtualization, the rendering tree, style calculation, and layout cache overhead continue to add up even if each message is small. Temporary nodes created by Markdown rendering and extra structures generated by code highlighting amplify the problem.

    4. Object URLs and large binary data not reclaimed. The PDF upload mentioned in the case is a detail worth noting. A common file upload implementation uses URL.createObjectURL to generate a preview URL. If URL.revokeObjectURL is not called, the corresponding binary data is retained permanently. Inlining large files as Base64 can also significantly increase memory usage.

    5. Unordered growth of closures and caches. Devtime travel debugging in state management libraries, full caching of request responses, and old scopes retained by debounce and throttle functions can all form reference chains that appear useful but actually leak memory.

    The following simplified code illustrates a common leak pattern in streaming processing:

    1. // Problematic: reader is not closed, and chunks are retained indefinitely
    2. async function readStream(response) {
    3. const reader = response.body.getReader();
    4. const chunks = [];
    5. while (true) {
    6. const { done, value } = await reader.read();
    7. if (done) break;
    8. chunks.push(value); // Keep appending, never release
    9. renderChunk(value);
    10. }
    11. // Missing reader.releaseLock(), and chunks are not cleared
    12. }
    13. // A safer version
    14. async function readStream(response) {
    15. const reader = response.body.getReader();
    16. try {
    17. while (true) {
    18. const { done, value } = await reader.read();
    19. if (done) break;
    20. renderChunk(value); // Keep only the data needed for rendering
    21. }
    22. } finally {
    23. reader.releaseLock();
    24. }
    25. }

    How to Systematically Troubleshoot Memory Leaks in Web Apps

    Based on this case, developers can establish a general troubleshooting workflow:

    1. Establish a baseline. Use the Memory panel in browser developer tools to record a heap snapshot shortly after the page loads as a baseline for comparison.

    2. Reproduce the scenario and take another snapshot. Perform typical operations such as several conversation rounds, file uploads, and session switching, then take another snapshot after a fixed interval, for example 15 minutes.

    3. Compare the deltas. Use the snapshot comparison view to observe which object types are growing continuously. An increase in detached DOM nodes usually points to event listeners or closures retaining references. Abnormal growth of ArrayBuffer or String points to binary data or streaming buffers not being released.

    4. Use the allocation timeline to locate the source. Enable allocation instrumentation on the timeline and observe which call stacks are responsible for memory allocations. This can pinpoint the specific functions.

    5. Validate with long-running stress tests. Use automation scripts to simulate scenarios such as “open the page and leave it idle” and “conduct continuous conversations.” Observe whether the memory curve converges to verify the fix.

    Memory Optimization Best Practices for AI Chat Web Apps

    For the special scenario of AI chat, which involves long sessions, rich content, and streaming rendering, the following practices are worth incorporating into engineering standards:

    • Virtualize message list rendering. Keep only message nodes near the viewport in the DOM. Store historical messages as data in memory or fetch them from the server on demand with pagination. This can reduce rendering overhead from O(n) to nearly O(1).

    • Clean up thoroughly when switching sessions. When switching to another session, abort in-flight streaming requests with AbortController, disconnect WebSockets, clear timers, and release file objects held by the old session.

    • Control boundaries for large file processing. Limit individual file size, revoke object URLs promptly after upload, and release decoded image or document data when preview components unmount.

    • Parse incrementally instead of re-rendering everything. For streaming Markdown output, parse incrementally as much as possible. Avoid reparsing and re-highlighting the entire answer every time a chunk arrives.

    • Set up memory monitoring and alerts. In test environments, use performance.memory or stricter automated memory tests to set threshold alerts. Include memory regressions in the CI process so leak issues do not remain undetected for more than a year.

    Lessons from the Case

    This incident offers two important reminders for the industry.

    First, the frontend engineering complexity of AI applications is underestimated. Streaming responses, rich text rendering, and multimodal file processing are layered on long-lived pages. A small mistake in memory management can produce an extreme case where simply opening a web page consumes 8 GB. Performance budgets should not focus only on first-screen load speed. Long-running memory stability is also a core metric.

    Second, response speed shapes reputation. User feedback persisted for more than a year before the issue was fixed. This reminds teams to establish a smooth feedback channel for performance issues and to give reports of “abnormal resource usage” the same priority as functional defects.

    For regular users, temporary mitigations in similar situations include closing unnecessary tabs promptly, avoiding keeping many sessions open in the same page for long periods, and refreshing the page when necessary to release accumulated memory. For developers, rather than waiting for users to expose the issue with screenshots, it is better to move memory stability testing earlier in the development process. That is the most valuable takeaway from this 8 GB memory incident.