# android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. # Open Cursors=10 (# cursors opened by this proc=10)

- **ID:** `android/room-cursor-window-allocation-failure`
- **Domain:** android
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 92%

## Root Cause

Too many open cursors without proper closure, exceeding the per-process cursor limit (typically 100) or memory limit.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Room 2.5.0 | active | — | — |
| SQLite 3.40.0 | active | — | — |
| Android 13 (API 33) | active | — | — |

## Workarounds

1. **Replace raw Cursor queries with Room's LiveData or Flow: @Query("SELECT * FROM users") fun getAllUsers(): LiveData<List<User>>. This ensures cursors are closed when lifecycle ends.** (95% success)
   ```
   Replace raw Cursor queries with Room's LiveData or Flow: @Query("SELECT * FROM users") fun getAllUsers(): LiveData<List<User>>. This ensures cursors are closed when lifecycle ends.
   ```
2. **If using raw Cursor, call cursor.close() in finally block and use ContentResolver.query with auto-close flag: val cursor = contentResolver.query(uri, null, null, null, null)?.use { it }** (85% success)
   ```
   If using raw Cursor, call cursor.close() in finally block and use ContentResolver.query with auto-close flag: val cursor = contentResolver.query(uri, null, null, null, null)?.use { it }
   ```

## Dead Ends

- **Increasing heap size in AndroidManifest with android:largeHeap=true** — Does not address cursor leak; heap size increase delays but doesn't prevent crash. (90% fail)
- **Adding try-finally blocks around cursor usage without using Room's LiveData or Flow** — Manual cursor management is error-prone; Room's reactive types handle lifecycle automatically. (70% fail)
