Advanced memory monitoring and leak detection for macOS, featuring intelligent orphan resource detection, runtime-specific diagnostics, and comprehensive data persistence.
- Real-time process tracking: Memory, CPU, I/O metrics
- Persistent snapshots: SQLite storage with WAL optimization
- System metrics: Memory pressure, swap usage, cache efficiency
- Process filtering: By name, PID, or network port
- Regression-based analysis: Statistical growth pattern detection
- High confidence: Only alerts on probable leaks, not normal variation
- Configurable thresholds: Customize for your workload (default: 50MB/24h)
- Historical trending: 3-day retention with configurable windows
- Chromium/Chrome/Electron: V8 heap dump analysis
- Node.js: Heap snapshot collection with leak patterns
- Xcode/Native: Malloc stack logs via xcrun xctrace
- Python: Memory profiler integration
- Extensible: Add custom runtimes via ToolchainAdapter protocol
- Deleted-but-open files: Find space-consuming deleted files still held by processes
- Stale swapfiles: Identify unused /var/vm accumulation
- Zombie processes: Report unreaped children
- Suspended processes: Find stuck applications
- Automated remediation: Specific cleanup commands
- Real-time metrics: Memory, swap, process count
- Historical sparklines: Memory/swap trends
- Quick actions: Open logs, launch diagnostics
- Accessibility: Full keyboard navigation and VoiceOver support
- Native SwiftUI: Zero JavaScript, pure native performance
# Build from source
cd MemoryWatchApp
swift build -c release
# Install to /usr/local/bin
cp .build/release/MemoryWatch /usr/local/bin/# View system memory status
memwatch status
# Start 1-minute monitoring session
memwatch monitor -d 60
# Analyze memory leaks from last 24 hours
memwatch leaks
# Detect orphaned resources
memwatch orphansMemoryWatch combines high-performance system monitoring with intelligent diagnostics:
ProcessMonitor (10s) → SystemMetrics → SQLiteStore (WAL)
↓
ProcessSnapshot
↓
LeakHeuristics (regression)
↓
MemoryAlert → ToolchainAdapter → Artifacts
↓
OrphanDetector (deleted files, swap, zombies)
↓
MenuBarApp (real-time UI)
Core Components:
- ProcessMonitor: Collects system snapshots every 10 seconds
- SystemMetrics: Gathers CPU, memory, I/O, swap statistics
- SQLiteStore: Persists data with WAL optimization for low latency
- LeakHeuristics: Regression-based growth pattern analysis
- OrphanDetector: Scans for orphaned resources
- ToolchainIntegration: Coordinates runtime-specific artifact capture
- MenuBarApp: SwiftUI real-time monitoring with accessibility
- CLI Reference - Full command documentation and examples
- SQLiteStore API - Database persistence API with code examples
- Developer Guide - Extending MemoryWatch with custom adapters
- Entitlements Guide - System permissions and security configuration
- Master Plan - Implementation roadmap and architecture decisions
# Show current status
memwatch status
# Top 20 processes by memory
memwatch status -n 20 --json > status.json
# Sort by CPU usage
memwatch status --sort cpu# Analyze last 24 hours
memwatch leaks
# Analyze specific process
memwatch leaks -p 1234 --confidence 80
# Check last 7 days with tight thresholds
memwatch leaks --time-window 168 --min-growth 10# Capture artifacts for Chrome process
memwatch diagnostics 1234
# Capture from all available runtimes
memwatch diagnostics 1234 --all-runtimes
# Save to custom directory
memwatch diagnostics 1234 -o /tmp/diagnostics# All orphaned resources
memwatch orphans
# Large deleted files only
memwatch orphans --deleted-files --min-size 100
# Identify stale swap
memwatch orphans --stale-swap# Start daemon with alerts
memwatch daemon --log /var/log/memorywatch.log --alerts
# Monitor with custom interval
memwatch monitor -i 5 --leak-detection
# Export data
memwatch export --format csv -o weekly_metrics.csv \
--start 2025-10-27 --end 2025-11-03Most commands support:
--json- JSON output for scripting--interval <N>- Check interval in seconds--threshold <MB>- Memory threshold--output <file>- Write to file
See CLI Reference for complete options.
# Data directory
export MEMORYWATCH_HOME=/var/log/memorywatch
# Log level
export MEMORYWATCH_LOG_LEVEL=debug
# Custom database
export MEMORYWATCH_DB=/path/to/custom.sqliteMemoryWatch stores all data in ~/MemoryWatch/:
| File/Directory | Purpose |
|---|---|
data/memorywatch.sqlite |
Main database with snapshots and alerts |
data/memorywatch.sqlite-wal |
Write-Ahead Log for fast writes |
data/artifacts/ |
Captured diagnostic artifacts (heap dumps, profiles) |
| Logs | Event logs and monitoring records |
- OS: macOS 12.0 or later
- Architecture: arm64 or x86_64
- Permissions:
- Full Disk Access (for orphan detection)
- Process monitoring (automatic)
- Notifications (optional, for alerts)
- Disk Space: ~100MB for 3 days of data
- Memory Overhead: ~20-30MB resident
- CPU Usage: <1% at 10-second intervals
- Disk I/O: ~2-5MB/hour
- Database Size: ~50MB per 24 hours
# Increase check interval
memwatch config --set update_cadence=30
# Reduce data retention
memwatch config --set retention_window_hours=24
# Disable expensive detection
memwatch monitor --no-leak-detectionPermission Denied Errors:
- Grant Full Disk Access: System Preferences > Security & Privacy > Full Disk Access
- Or use
sudo memwatch orphans
High CPU Usage:
- Increase monitoring interval:
memwatch monitor --interval 30 - Disable leak detection:
--no-leak-detection
Database Errors:
- Check health:
memwatch status - Reset:
rm ~/MemoryWatch/data/memorywatch.sqlite
See Troubleshooting Guide for more issues.
memwatch export --format json | jq '.snapshots[]' | \
curl -X POST http://influxdb:8086/write -d @-memwatch monitor --output /tmp/memwatch.log &
tail -f /tmp/memwatch.log | grep "CRITICAL" | \
while read line; do
curl -X POST $SLACK_WEBHOOK -d "{\"text\":\"$line\"}"
done// Access raw data via SQLiteStore
let store = try SQLiteStore(url: databaseURL)
let snapshots = store.getRecentSnapshots(hoursBack: 24)
let alerts = store.getAlerts(hoursBack: 24)MemoryWatch is designed for extension:
- Custom Adapters: Implement
ToolchainAdapterfor new runtimes - Custom Detectors: Extend leak detection with your heuristics
- Database Access: Query raw data via
SQLiteStoreAPI - CLI Extensions: Add custom commands via command registry
See Developer Guide for details.
We chose Swift for system monitoring because:
- Native Performance - Direct macOS system API access with zero overhead
- Lightweight - Single binary (~3MB), no runtime dependencies
- Type Safety - Compile-time guarantees for system-level code
- Fast Startup - Instant execution, no interpreter overhead
- Accessibility - VoiceOver/keyboard support in menu bar UI
- No Bloat - Pure native code, zero JavaScript dependencies
Contributions welcome! Areas of interest:
- Additional runtime adapters (Go, Rust, Java, PHP)
- Advanced leak detection heuristics
- Performance optimizations
- Documentation improvements
- Localization support
MIT License - See LICENSE file
- Phase 1: Core monitoring with SQLite persistence
- Phase 2: Hardening & telemetry (maintenance, retention, health monitoring)
- Phase 3: Toolchain integrations (Chrome, Node, Xcode, Python adapters)
- Phase 4: Orphan detection (deleted files, stale swap, zombies)
- Phase 5: Documentation & developer experience
- Phase 6: Production deployment (code signing, notarization, distribution)
- REST API for remote monitoring
- WebUI dashboard
- Kubernetes integration
- Time series database backend plugins
- Issues: Report bugs on GitHub
- Discussions: Ask questions in GitHub Discussions
- Docs: See
/docsdirectory for comprehensive guides
Status: Active Development Last Updated: November 2025 Maintainer: MemoryWatch Team