Cause and mechanism
ScrollRect is the uGUI component for scrolling a list. Creating every row, including those off screen, increases memory use and automatic layout work. Reuse a small set of visible rows and a few spare rows as the list scrolls. Measure the result because the way cost grows depends on the UI's structure.
Check and correct the setup
- For fixed-height lists, keep only visible cells plus a small buffer after profiling layout work.
Change one variable, then remeasure - Compute content height and first visible index, then reuse cells and bind new data. Empty lists need zero height.
Update position and displayed data - Variable-height lists need a suitable height/index lookup. Handle resizing, fast jumps, last rows, and data changes; reset events and stale images.
Update position and displayed data
Limits and verification
Removing automatic layout does not remove text/graphic update cost. Benefits depend on item count and updates.
A focused diagnostic setup
Use a fixed-height exercise without spacing/padding: one thousand rows at height twenty-four gives a content height of 24000, while only visible rows plus a buffer need cell objects.
Test in this order
- Derive and clamp the first visible data index from scroll position rather than allocating one cell per item.
Update position and displayed data - Refresh text, images, selection and event bindings when a cell changes data identity.
Update position and displayed data - Test empty/final rows, rapid scrolling, resizing and deletion, recalculating layout as needed.
Update position and displayed data
Interpret the result
Variable-height content needs measured/cumulative heights rather than the fixed formula. Verify stable cell count and absence of stale images or click destinations.