High memory footprint after long uptime: heap breakdown & source code locations
- Dominant language
- Swift
- Stars
- 14.7k
- Forks
- 469
- PR merge metrics
- No merged PRs in 30d
Description
### Summary
After long continuous uptime, Hidden Bar's memory footprint in Activity Monitor can grow to 600MB+. Diagnostic tools (`footprint` & `heap`) reveal that while active Resident Memory (RSS) remains small (~50MB), the process accumulates ~190k malloc nodes and ~500MB of swapped/compressed dirty pages.
### Diagnostic Findings (`footprint` & `heap`)
- **Total Malloc Nodes**: ~193,000 nodes (MALLOC_SMALL count ~159,700)
- **Top Allocated Types**:
- `NSMutableDictionary` / `CFData`: 6,000+ instances
- `__NSMallocBlock__`: 3,200+ instances
- `CAContext._impl` (QuartzCore layer contexts): 800+ instances
### Corresponding Source Locations
1. **`StatusBarController.swift` (lines 125-144)** — `setupHoverToExpandIfEnabled`
- High-frequency global mouse movement monitoring (`NSEvent.addGlobalMonitorForEvents(matching: .mouseMoved)`) accumulates `NSMutableDictionary` and `CFData` event wrapper instances over long runtimes.
2. **`StatusBarController.swift` (lines 316-329)** — `startTimerToAutoHide`
- When deferring auto-collapse (e.g., when the mouse is in the menu bar), repeatedly invalidating and re-scheduling single-shot `Timer` instances creates new closure blocks, accumulating `__NSMallocBlock__` and dispatch continuations.
3. **`Assets.swift` (lines 13-26)** & **`StatusBarController.swift` (lines 270, 281)**
- `Assets.expandImage` / `collapseImage` are computed properties evaluating `NSImage(named:)` dynamically. Re-assigning `button.image` on expand/collapse actions repeatedly rebinds AppKit button layer contexts, accumulating `CAContext._impl` instances.
4. **`StatusBarController.swift` (line 342)** — `getContextMenu`
- `NotificationCenter.default.addObserver` is invoked inside menu construction, which may add duplicate observers if the context menu is re-instantiated.
Hope this diagnostic breakdown helps!
Contributor guide
Research direction
Start with StatusBarController.swift at setupHoverToExpandIfEnabled, startTimerToAutoHide, getContextMenu, and the image assignments at lines 270 and 281; compare these paths with Assets.swift lines 13-26. Reproduce long uptime and inspect the process with footprint and heap, then verify that the reported malloc nodes, blocks, layer contexts, and memory growth no longer accumulate.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- desktop, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100