Skip to content

[Enhancement] Add memory pressure auto-cleanup service to prevent OOM kills on low-end devices #661

Description

@RUKAYAT-CODER

Overview

The app targets users on low-end Android devices (2GB RAM common in target markets). Long sessions accumulate memory from image caches, metrics buffers, search indexes, and Redux-like subscription closures. No cleanup mechanism exists to respond to OS memory pressure warnings. iOS calls didReceiveMemoryWarning and Android fires onTrimMemory; ignoring these leads to OOM process kills.

Specifications

Features:

  • memoryPressureService subscribes to native memory warning events
  • On warning: flush metrics buffers, clear non-critical image cache, compact search index
  • Expose memoryPressureLevel in deviceStore (normal, warning, critical)
  • critical level triggers degradationStore.disableFeature for high-memory features

Tasks:

  • Create src/services/memoryPressureService.ts
  • Use AppRegistry.registerHeadlessTask or RN's internal 'memoryWarning' event
  • On warning, call imageCache.clearNonCritical(), metricsService.flush(), searchIndex.compact()
  • Dispatch setMemoryPressureLevel to deviceStore
  • Add unit test simulating memory warning event

Impacted Files:

  • src/services/memoryPressureService.ts (create)
  • src/store/slices/deviceStore.ts
  • src/store/slices/degradationStore.ts

Acceptance Criteria

  • Memory warning event triggers cleanup of non-critical caches
  • deviceStore.memoryPressureLevel updates on warning
  • Critical pressure disables at least one high-memory feature via degradationStore
  • Unit test confirms cleanup methods called on warning event

Metadata

Metadata

Assignees

No one assigned

    Labels

    Stellar WaveIssues in the Stellar wave programenhancementNew feature or requestperformancePerformance issue or optimization

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions