Skip to content

High memory footprint after long uptime: heap breakdown & source code locations #386

Description

@sususu98

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions