[Bugfix] GridData::views leaks expired weak_ptrs — ~UIGridView never unregisters #362
Labels
No labels
Alpha Release Requirement
Bugfix
Demo Target
Documentation
Major Feature
Minor Feature
priority:tier1-active
priority:tier2-foundation
priority:tier3-future
priority:tier4-deferred
Refactoring & Cleanup
system:animation
system:documentation
system:grid
system:input
system:performance
system:procgen
system:python-binding
system:rendering
system:ui-hierarchy
Tiny Feature
workflow:blocked
workflow:needs-benchmark
workflow:needs-documentation
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
john/McRogueFace#362
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Found by adversarial review of the #355/#359 branch (
feat/355-grid-input-revival,85e4bbe). Reported as minor; not fixed there.Defect
GridData::views(src/GridData.h) is the N-view registry that replacedowning_viewin #359. Entries are only ever removed byGridData::unregisterView, which is reached from exactly two places:UIGridView::set_grid(reassigning a view's data), andPyUIGridViewType.tp_dealloc, gated onobj->data.use_count() <= 1(the #251 pattern).~UIGridViewitself does not callunregisterView. So whenever the C++ view outlives its Python wrapper — the normal case when a scene holds the lastshared_ptr— the wrapper is deallocated withuse_count() > 1, the guard skips the unregister, and when the view is finally destroyed by scene removal its entry stays inviewsforever as an expiredweak_ptr.registerViewnever prunes either (it only scans for duplicates).Consequence
viewsgrows without bound across the lifetime of aGridData. EverymarkDirty()/markCompositeDirty()then iterates the dead entries andlock()s each one — so a long-running scene that repeatedly creates and destroys views over one persistent GridData pays a growing per-mutation cost, and the vector never shrinks.Not a correctness bug (expired
weak_ptrslock()to null and are skipped), which is why it was ranked minor — but it is an unbounded leak on a hot path (markDirtyis called on every entity move).Fix
Call
grid_data->unregisterView(this)from~UIGridView(), which is the only place guaranteed to run exactly once per view. Consider also pruning expired entries opportunistically inregisterView.Test
A regression test should create and destroy N views over one persistent GridData and assert the registry does not grow (needs a way to observe
views.size()— either a debug accessor or an indirect assertion viamarkDirtycost).