{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

ViewCompositionStrategy.DisposeOnDetachedFromWindow

public static class ViewCompositionStrategy.DisposeOnDetachedFromWindow implements ViewCompositionStrategy


ViewCompositionStrategy that disposes the composition whenever the view becomes detached from a window. If the user of a Compose UI view never explicitly calls AbstractComposeView.createComposition, this strategy is always safe and will always clean up composition resources with no explicit action required - just use the view like any other View and let garbage collection do the rest. (If AbstractComposeView.createComposition is called while the view is detached from a window, AbstractComposeView.disposeComposition must be called manually if the view is not later attached to a window.)

Summary

Public fields

static @NonNull ViewCompositionStrategy.DisposeOnDetachedFromWindow

Public methods

@NonNull Function0<Unit>

Install this strategy for view and return a function that will uninstall it later.

Public fields

INSTANCE

public static @NonNull ViewCompositionStrategy.DisposeOnDetachedFromWindow INSTANCE

Public methods

installFor

public @NonNull Function0<UnitinstallFor(@NonNull AbstractComposeView view)

Install this strategy for view and return a function that will uninstall it later. This function should not be called directly; it is called by AbstractComposeView.setViewCompositionStrategy after uninstalling the previous strategy.