Skip to content

View Binding proposals and Leak Canary integration

cyberta requested to merge view_binding into main

As a respond to !32 (comment 2903718), I had another look at Googles Android Developers Guides about view binding.

One problem we need to address is that the lifecycle of the Fragment outlives the views lifecycle, which leads to memory leaks.

For what I've read is there are 2 main recommended patterns for Fragments:

In any case we should avoid initializing view bindings for fragments using lateinit since that is a guarantee for a leak.

This MR proposes to change the use of view bindings so that one of the two patterns is always used, depending on whether we want to hold a reference to the binding object or not

It also adds LeakCanary to detect possible memory leaks early in the development cycle. LeakCanary is only added to debug builds, and only if they are not running as instrumentation tests.

(possible circular dependencies due to the implementation of the click handler in the fragment hasn't been yet addressed) Using a local scoped view binder should also resolve circular dependencies related to the click handler.

@ankitgusai19 I'm curious to hear your opinion

Edited by cyberta

Merge request reports