Memory leak in CameraAnimatorsRunner (11.31.1)
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 55/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- swift
- Domain
- performance
Research direction
Start in Sources/MapboxMaps/Camera/CameraAnimatorsRunner.swift: add(_ animator:) appends each onCameraAnimatorStatusChanged subscription to cancelables and nothing prunes them, so entries outlive their animators. Read how AnyCancelable and ClosureHandlersStore interact to find a safe point to drop cancelled subscriptions (the suggested pruning on next add() is one option). Verify with Instruments/leak counts over a simulated navigation run, mimicking the growth of ClosureHandlersStore<CameraAnimatorStatus, ()> described in the report; done means instance counts stay flat over a long run.
Written by the indexing model from the issue text.
Description
Versions: mapbox-maps-ios 11.31.1 with mapbox-navigation-ios 3.31.1. CameraAnimatorsRunner.swift on main is byte-for-byte the same as in 11.31.1.
In Sources/MapboxMaps/Camera/CameraAnimatorsRunner.swift, add(_ animator:) stores each animator's onCameraAnimatorStatusChanged subscription in the cancelables set. Nothing ever removes it, so every subscription stays alive until the MapView is deallocated, even after the animator itself has been released. The AnyCancelable returned by ClosureHandlersStore.add(handler:) holds a strong reference to the animator's ClosureHandlersStore and its handler, so each animator leaves behind two NSLocks.
During navigation this grows non-stop. In following mode, NavigationCameraStateTransition.update(to:state:) in the Navigation SDK creates 2-6 new animators on every camera update (zoom and padding are animated even when unchanged), about 5 times a second.
Measured: ClosureHandlersStore<CameraAnimatorStatus, ()> instances grew from 132 to 11,645 over about 2,300 s of simulated driving (about 6 MB). AnyCancelable, ObjectWrapper and NSLock grew at the same rate. There was only one CameraAnimatorsRunner the whole time.
Suggested fix: remove a subscription once its animator has been released, for example by pruning the set on the next add() call. This doesn't change how the camera behaves.
- Dominant language
- Swift
- Stars
- 601
- Forks
- 198
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from mapbox/mapbox-maps-ios
-
bug :beetle:
Difficulty 5/5 Over a week Newbie friendliness 12/100
mapbox/mapbox-maps-ios#2453 ·
-
auto-triaged bug :beetle: p3 SwiftUI
Difficulty 4/5 3-5 days Newbie friendliness 48/100
mapbox/mapbox-maps-ios#2452 · 6 reactions ·
-
auto-triaged bug :beetle: p2
Difficulty 4/5 3-5 days Newbie friendliness 42/100
mapbox/mapbox-maps-ios#2451 ·
-
auto-triaged bug :beetle: needs info p3 performance :zap:
Difficulty 5/5 Over a week Newbie friendliness 22/100
mapbox/mapbox-maps-ios#2450 · 1 comment ·
-
auto-triaged bug :beetle: p1
Difficulty 4/5 3-5 days Newbie friendliness 35/100
mapbox/mapbox-maps-ios#2449 · 5 comments ·
All issues in mapbox/mapbox-maps-ios
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
-
area: agents
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
manaflow-ai/cmux#29762 · 1 comment ·
Maintainers usually reply within 1 day
-
AI summaries can show reasoning text instead of the answerPossibly taken @yashiels claimed this today. Openclawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P2
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
steipete/RepoBar#156 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Lakr233/vphone-cli#791 ·
Maintainers usually reply within 1 day