Repository navigation
Description
Problem
After a large result is closed, the app does not return to the memory it started with. Measured on SELECT * FROM trips_1m (1M x 20, Execute Without Limit) on PostgreSQL, phys_footprint:
- 573 MB before the run. That figure came from an earlier 1M-row result that had already been closed.
- 1,262 MB with the result open.
- 277 MB after closing the tab.
So the first closed result still held at least 296 MB (573 - 277) when the second run started. That the footprint then fell below 573 MB suggests the second run reused that memory and gave part of it back. The MySQL run started at 257 MB. A fresh launch's footprint was not recorded in this run. This is an investigation first: the cause is either a live reference that keeps rows alive, or the allocator keeping freed pages.
Cause
Unknown. What the code shows:
- A user close (
closeTabsByUser,apple/TablePro/Views/Main/Extensions/MainContentCoordinator+TabClosing.swift:10-24) removes the tab, and the tabs setter unregisters its session (apple/TablePro/Models/Query/QueryTabManager.swift:250-256,apple/TablePro/Models/Query/TabSessionRegistry.swift:20-22), on the main actor. Other paths clear rows withremoveTableRows(TabSessionRegistry.swift:76-82). - Other holders of a result's rows or of per-row state, each to check after a close:
- the tab's
ResultSetobjects (apple/TablePro/Models/Query/ResultSet.swift:30), which share the session buffer while active (apple/TablePro/Views/Main/Extensions/MainContentCoordinator+TableRowsMutation.swift:149-155); - the grid model and display caches in
dataGridEntries, pruned bycleanupTabCaches(MainContentCoordinator+TabClosing.swift:67-70); RowPositions, which holds a[RowID: Int]entry per row after a sort or a mid-result insert (apple/TablePro/Models/Query/RowPositions.swift:13,:35-43).
- the tab's
- A result of this shape is about 1M row buffers of 896 B, 2M heap strings and a 32 MB row index, all small and medium malloc blocks. phys_footprint keeps counting those regions' dirty pages until malloc hands them back to the system.
Change
First measure, then fix what the measurement names.
- Fresh launch: connect, then record
footprint <pid>,vmmap --summary <pid>andheap <pid>. - Run the query, then record the same three.
- Close the tab. Record again after 10 s and after 2 minutes.
- In
heap, count_ContiguousArrayStorage<PluginCellValue>,StringStorage,TableRowsandResultSetinstances.- If about 1M row arrays are still alive, a reference holds them. Take a memory graph (
leaks <pid> --outputGraph=closed.memgraph) and follow one row array to its root in Xcode's memory graph debugger. - If the objects are gone but footprint stays high, compare the
MALLOC_TINY,MALLOC_SMALLandMALLOC_NANOdirty sizes invmmap. Then callmalloc_zone_pressure_relief(NULL, 0)once from lldb and readfootprintagain. A drop means allocator retention.
- If about 1M row arrays are still alive, a reference holds them. Take a memory graph (
- Repeat open and close 5 times. Footprint that grows per cycle is a leak. Footprint that levels off is retention.
- Run it once more on MySQL.
Then:
- A live reference: release it at the one place that owns it, and add a test that a closed tab's
TableRowsandResultSetare deallocated (a weak reference that goes nil). - Allocator retention: do not add pressure-relief calls or timers to the app. The cause is millions of small heap blocks per result. perf(results): hold every Mac result in the core's columnar store #4521's chunked columns hold a few large buffers that go back to the system when freed. Record the numbers on perf(results): hold every Mac result in the core's columnar store #4521, and add "footprint returns to the pre-run level after close" to its checks.
Overlaps #4453: L1 measures memory after a connection window closes (coordinators, workspaces, split views). It does not measure a closed tab's rows.
Measure
- The table from steps 1 to 5 for PostgreSQL and MySQL, before and after the fix: footprint at launch, with the result, and 2 minutes after close.
- Target: footprint 2 minutes after close is back at the pre-run level, within the spread of five repeated pre-run readings.
Part of the performance plan.
Activity
datlechin commentedon Nov 26, 2026
#4598 adds the test this issue asks for on the live-reference branch: a closed tab's
ResultSet(weak reference) and its row buffer (uniquely held after the close) are gone, for the last tab and for one of two, through the real run and close paths. Left: the footprint table (launch, with the result, 10 s and 2 min after close, five cycles, PostgreSQL and MySQL) and themalloc_zone_pressure_reliefreading, which need the real app against a live server. The shared Mac ran out of disk during this run, so they were not taken. If #4598 is green, the objects are released at close and the rest is allocator retention for #4521.