Memory Overhead of Memoized Components
What you'll learn: How React.memo stores previous props in memory and why memoizing too many components can increase your app's memory footprint.
The Memory Cost of Memoization
When you wrap a component with React.memo, React doesn't just magically skip renders for free. Behind the scenes, it stores a snapshot of the component's previous props in memory so it can compare them on the next render.
Think of it like keeping a photocopy of every document before you decide whether to print a new version. That photocopy takes up space in your filing cabinet (memory).
How It Accumulates
For a single memoized component, the memory overhead is negligible—we're talking about storing prop values. But consider this: if you wrap 100 components in React.memo across your application, React is now maintaining 100 separate "snapshots" of prop values. Each one occupies memory.
The Hidden Cost
The memory overhead includes:
- The previous props object itself
- Any nested objects or arrays in those props
- React's internal bookkeeping structures for comparison
If your memoized component receives large objects or arrays as props, those values must be retained in memory between renders for comparison purposes.
When It Matters
On modern devices with gigabytes of RAM, memoizing dozens of components won't cause issues. But on memory-constrained devices (older phones, low-end tablets), or in apps with hundreds of memoized components, this overhead can compound and contribute to performance degradation or even crashes.
Key Takeaway: React.memo trades memory for CPU cycles—it stores previous props to avoid re-render work. Memoize strategically where re-renders are expensive, not everywhere by default.