Skip to content

Memory leak in getFilteredRowModel - heap not released after filter removal (React) #6170

@aligorgeldev

Description

@aligorgeldev

TanStack Table version

v8.21.3

Framework/Library version

v19.2.0

Describe the bug and the steps to reproduce it

Describe the bug

When using getFilteredRowModel() in React, applying and then removing a filter
causes a permanent memory increase. The allocated heap is never garbage collected
after the filter is cleared.

Versions

  • @tanstack/react-table: 8.21.3
  • react: 19.2.0
  • Browser: Chrome (latest)

Steps to reproduce

  1. Set up a table with getFilteredRowModel() and column filters
  2. Open Chrome DevTools → Memory → Take heap snapshot (baseline)
  3. Apply a filter to any column
  4. Remove the filter
  5. Force garbage collection (GC button in Memory tab)
  6. Take another heap snapshot

Expected behavior

Memory should return to baseline after filter is removed and GC runs.

Actual behavior

Memory stays ~100mb above baseline permanently. Each filter apply/remove cycle
keeps the heap elevated. Heap snapshot shows retained objects:

  • PerformanceMeasure × 128,000+
  • Error × 21,000+ (React debug stack traces)
  • FiberNode × 22,000+

Workaround

We worked around this by bypassing getFilteredRowModel entirely and implementing
client-side filtering manually via useMemo on the data before passing to
useReactTable. This completely eliminates the memory issue.

// Instead of getFilteredRowModel(), we do:
const filteredData = useMemo(() => {
  if (columnFilters.length === 0) return data
  return data.filter(row => {
    return columnFilters.every(filter => {
      // custom filter logic per type
    })
  })
}, [data, columnFilters])

const table = useReactTable({
  data: filteredData, // filtered data passed directly
  // no getFilteredRowModel()
})

Additional context

The issue appears to be in the internal caching mechanism of getFilteredRowModel.
Filtered row arrays are not released even after the filter state is cleared.

Your Minimal, Reproducible Example - (Sandbox Highly Recommended)

https://stackblitz.com/edit/vitejs-vite-fpa64u99?file=src%2FApp.tsx

Screenshots or Videos (Optional)

No response

Do you intend to try to help solve this bug with your own PR?

No, because I do not have time to dig into it

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.

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