Roo-Code/webview-ui
Roo Code f7eba8fb60 Fix #4890: Resolve grey screen crashes through comprehensive memory management
This commit addresses the grey screen issue that occurs every 15-20 minutes by implementing comprehensive memory leak fixes and proactive memory management:

**Root Cause Analysis:**
- LRU cache with excessive size (250 items) and long TTL (15 minutes) causing memory buildup
- Timer leaks in WorkspaceTracker where timers weren't properly nullified after clearing
- Insufficient resource cleanup in Task and ClineProvider disposal methods
- Lack of proactive memory management and pressure detection

**Memory Management Improvements:**

1. **LRU Cache Optimization** (ChatView.tsx):
   - Reduced cache size from 250 to 100 items
   - Shortened TTL from 15 minutes to 5 minutes
   - Added periodic cleanup every 2 minutes to prevent accumulation

2. **Timer Leak Fixes** (WorkspaceTracker.ts):
   - Fixed timer management by properly nullifying resetTimer and updateTimer after clearing
   - Prevents memory leaks from dangling timer references

3. **Enhanced Resource Disposal**:
   - Task.ts: Improved dispose() with comprehensive memory clearing and error handling
   - ClineProvider.ts: Enhanced disposal methods with better error handling and resource cleanup

4. **Proactive Memory Management System**:
   - Created MemoryManager utility (src/utils/memoryManager.ts) for centralized cleanup
   - Singleton pattern with periodic garbage collection and resource cleanup
   - Integrated into extension lifecycle for automatic management

5. **Memory Pressure Detection** (App.tsx):
   - Added webview-side memory monitoring using browser performance APIs
   - Checks memory usage every 2 minutes and triggers cleanup at 75% threshold
   - Communicates memory pressure to extension for reactive cleanup

6. **Message Handling Enhancement**:
   - Added memoryPressure message type to WebviewMessage.ts
   - Implemented memory pressure handler in webviewMessageHandler.ts
   - Triggers aggressive cleanup for critical memory usage (>90%)

**Technical Implementation:**
- Uses browser performance.memory API for accurate memory tracking
- Implements both reactive (pressure-based) and proactive (periodic) cleanup strategies
- Maintains backward compatibility with existing functionality
- Includes comprehensive test coverage for MemoryManager

**Testing:**
- Added unit tests for MemoryManager functionality
- Verified timer cleanup and resource disposal patterns
- Tested memory pressure detection and cleanup triggers

This solution prevents the grey screen crashes by addressing memory accumulation before it reaches critical levels, ensuring stable long-term operation of the Roo Code extension.
2025-06-19 17:00:01 +00:00
..
audio feat: move play audio to webview to ensure cross-platform (#3659) 2025-05-20 01:15:05 -04:00
public Remove CRA cruft 2025-01-30 14:38:41 -08:00
src Fix #4890: Resolve grey screen crashes through comprehensive memory management 2025-06-19 17:00:01 +00:00
.gitignore PR cleanup 2025-03-12 11:23:06 -04:00
components.json Remove lucide 2025-01-30 14:47:59 -08:00
eslint.config.mjs Preserve model settings when selecting a specific OpenRouter provider (#3915) 2025-05-23 23:22:41 -07:00
index.html Fix linter warning + run prettier on everything (#3581) 2025-05-13 15:16:24 -07:00
jest.config.cjs feat(mcp): improve mcp with McpExecution, make UX like terminal execute (#3485) 2025-06-12 00:46:07 -04:00
package.json Bump @roo-code/types to v1.26.0 (#4584) 2025-06-12 11:05:53 -04:00
tsconfig.json Add a new @roo-code/types package and use it everywhere (#3912) 2025-05-26 12:06:45 -07:00
turbo.json Improve turbo task dependency declarations (#4323) 2025-06-04 09:32:27 -07:00
vite.config.ts Marketplace (#4538) 2025-06-11 17:28:12 -04:00