Skip to content

Conversation

@mauricecarrier7
Copy link
Contributor

What's this do?

  • Improves pagination order on More view
  • Resolves cache crashes

Why are we doing this? (w/ Notion link if applicable)
Improve user experience

How should this be tested? / Do these changes have associated tests?
Follow steps in ticket

Dependencies for merging? Releasing to production?
N/A

Does this include changes that require a new Palace build for QA?
Yes

Has the application documentation been updated for these changes?
N/A

Did someone actually run this code to verify it works?
@mauricecarrier7

- Added totalCostLimit and countLimit to all NSCache instances
- GeneralCache: 50-150MB limit per instance based on device memory
- TPPEncryptedPDFDocument: 30-80MB limit for PDF thumbnails
- Added cost tracking for all cache setObject calls
- Decentralized memory warning handling (each cache manages itself)
- Removed redundant clearAllCaches() call from MemoryPressureMonitor
- Changed to async memory clearing to avoid blocking main thread

This prevents NSMallocException 'Failed to grow buffer' crashes that occur
when removeAllObjects() is called on unbounded caches during memory pressure.
Limits are generous and won't impact normal usage or downloads.
- PDF Text Extractor: Replaced string += concatenation with array.joined()
- Added 50KB block size limit to prevent unbounded text extraction
- Pre-allocate array capacity for better performance
- Added size guards to break out of loops before hitting memory limits

- Audiobook Logger: Added 2MB file size limit to prevent unbounded growth
- Truncate log retrieval to last 1MB for large files
- Use FileHandle streaming instead of loading entire files into memory

These changes prevent NSMallocException '__CFStringHandleOutOfMemory' crashes
that occur when string buffers grow too large during PDF parsing or log operations.
@mauricecarrier7 mauricecarrier7 self-assigned this Oct 22, 2025
@mauricecarrier7 mauricecarrier7 marked this pull request as ready for review October 22, 2025 13:56
@mauricecarrier7 mauricecarrier7 merged commit 4ae9ab6 into develop Oct 22, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants