Skip to content

Kotlin - lateinit memory leak issues #234

Open
@ZakTaccardi

Description

@ZakTaccardi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @dimsuz@sevar83@ZakTaccardi@sockeqwe@PaulWoitaschek

        Issue actions

          Kotlin - lateinit memory leak issues · Issue #234 · bluelinelabs/Conductor