arkavo-org / arkavo-org/app

🔴 CRITICAL: Fix memory leaks in NotificationCenter observers

Open
#207 0 comments 0 reactions 0 assignees View on GitHub
bug tech debt
Dominant language
Swift
Stars
0
Forks
0
Avg merge
1h 41m
Merged PRs (30d)
1

Description

## Problem

ViewModels use manual `NotificationCenter` observer management without proper cleanup, causing memory leaks.

## Affected Files

| File | Lines | Issue |
|------|-------|-------|
| `ChatViewModel.swift` | 38-42, 93-97 | Manual observer cleanup in deinit |
| `VideoFeedViewModel.swift` | Multiple | Observer lifecycle issues |
| `GroupViewModel.swift` | Multiple | 20+ notification observers |

## Current Implementation

```swift
// ChatViewModel.swift
deinit {
MainActor.assumeIsolated {
notificationObservers.forEach { NotificationCenter.default.removeObserver($0) }
}
}
```

## Impact

- **Severity**: Critical
- **Risk**: Memory pressure leading to crashes in long sessions
- **User Impact**: App becomes slow/crashes during extended chat sessions

## Solution

1. Replace `NotificationCenter` observers with Combine publishers
2. Use `@Published` properties where appropriate
3. Store cancellables in `Set` for automatic cleanup
4. Audit all ViewModels for observer leaks

## Acceptance Criteria

- [ ] All ViewModels use Combine instead of NotificationCenter
- [ ] No manual `removeObserver` calls needed
- [ ] Memory profiling shows no leaks in chat scenarios

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reviewing the observer setup and cleanup in ChatViewModel.swift, then compare the lifecycle handling in VideoFeedViewModel.swift and GroupViewModel.swift. Audit the listed ViewModels against the stated observer-lifecycle problem and acceptance criteria. Done means the ViewModels use Combine, manual removeObserver calls are unnecessary, and memory profiling shows no leaks in chat scenarios.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.