Skip to content

Start: Memory Leak with TanStack Form #5734

@checkerschaf

Description

@checkerschaf

Which project does this relate to?

Start

Describe the bug

I'm experiencing a significant memory leak when using TanStack Form with Start in production. It crashes my production server every 30 minutes because memory is not being cleaned up for pages that utilize any form.

This issue may also affect other packages. I focused on creating a reproducer with TanStack Form since it's commonly used.

Your Example Website or App

https://github.com/checkerschaf/tanstack-start-form-memory-leak

Steps to Reproduce the Bug or Issue

Setup the project

  1. Run npm install
  2. Run npm run build
  3. Run npm run start

How to get the heap snapshots

Open http://localhost:3000/form to load the page once and get the base memory usage.

Then open http://localhost:3000/heap-snapshot to get the heap snapshot.

Run the script to load the page 10000 times:

oha http://localhost:3000/form -n 10000 -c 100

Then open http://localhost:3000/heap-snapshot to get the heap snapshot.

How to analyze the heap snapshots

Open the heap snapshot in Chrome DevTools and click on the "Memory" tab.

Load both snapshots and compare the differences.

Sort by "Size Delta" to see the biggest differences first. Clicking on the row will show that there is still a reference to many objects that are not being garbage collected.

This is not happening on other routes like /posts.

Expected behavior

No memory leak 😄

Other pages, such as /posts, do not leak much memory.

Screenshots or Videos

Image

Platform

  • Start Version: 1.134.9
  • OS: macOS
  • Form: 1.23.8

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions