cashapp / sqldelight

SQLDelight - Generates typesafe Kotlin APIs from SQL
https://cashapp.github.io/sqldelight/
Apache License 2.0
6.14k stars 514 forks source link

Possible leak when using OffsetQueryPagingSource + Pager? #4372

Open dellisd opened 1 year ago

dellisd commented 1 year ago

Discussed in https://github.com/cashapp/sqldelight/discussions/4366

Originally posted by **nabrozidhs** July 13, 2023 I think there might be a memory leak when using sqldelight (2.0.0-rc02) + Pager, or it could be that I'm using it wrong so I didn't want to create a bug report until someone can tell me whether the code looks fine or not...I've created a project that reproduces the issue https://github.com/nabrozidhs/sqldelight_leak The current implementation of LeakActivity has a memory leak. OffsetQueryPagingSource when used with Pager does not call the unregister method from sqldelight's android driver when the activity finishes. This is the method not being called https://github.com/cashapp/sqldelight/blob/master/drivers/android-driver/src/main/java/app/cash/sqldelight/driver/android/AndroidSqliteDriver.kt#L92. To test it launch the app, tap the button, and then press back when prompted. LeakCanary should eventually detect the leak. I wanted to confirm whether I'm doing something obvious wrong before submitting a bug report. I uploaded a leak trace too https://github.com/nabrozidhs/sqldelight_leak/blob/main/leaktrace.txt
nabrozidhs commented 1 year ago

I updated my test repo to latest paging 3.2.0 + sqldelight 2.0.0 and the issue is still reproducible. Let me know if there is anything else I can do to help!

nabrozidhs commented 1 year ago

I've updated the test repo again with latest paging 3.2.1 and the leak is still happening. Please let me know if there is anything I can do to help, as it's the only thing preventing me from updating to sqldelight 2 + paging 3.