bluelinelabs / bluelinelabs/Conductor
Kotlin - lateinit memory leak issues
- Dominant language
- Java
- Stars
- 3.9k
- Forks
- 338
- PR merge metrics
- No merged PRs in 30d
Description
Conductor should boldly advertise (I don't think it's made obvious enough for new users) that its instances survive configuration changes (stark contrast to `Activity/Fragment/View`) - this has huge implications for dagger + kotlin users.
```
class SalesController : BaseController, SalesView {
@Inject lateinit var viewBinder: SalesController.ViewBinder
@Inject lateinit var renderer: SalesRenderer
@Inject lateinit var presenter: SalesPresenter
lateinit private var component: SalesScreenComponent
override var state = SalesScreen.State.INITIAL //only property that I want to survive config changes
fun onCreateView(): View { /** lateinit variables are set here */ }
fun onDestroyView() { /** lateinit variables need to be dereferenced here, or we have a memory leak */ }
}
```
My `lateinit` properties are injected by dagger, and I need to set them to `null` in `onDestroyView` - or have a memory leak. This however is not possible in kotlin, as far as I am aware (without reflection). I could make these properties nullable, but that would defeat the purpose of Kotlin's null safety.
I'm not quite sure how to solve this. Ideally there could be some type of annotation processor that would null out specific variables automatically in `onDestroyView`
Contributor guide
Research direction
The issue names no files, tests, or entry points. Start by reading Conductor's controller lifecycle around onCreateView and onDestroyView, then review the Kotlin and Dagger usage described in the example. Done would require an agreed approach for preventing retained view-related references and making Conductor's configuration-change behavior clear to users.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 20/100