rive-android icon indicating copy to clipboard operation
rive-android copied to clipboard

Fix leaking issue when add lifecycle observer

Open hoangthan opened this issue 2 years ago • 4 comments

Since the context is using ActivityLifeCycle. So trying to add lifeCycleObserver without remove when the view is being detached will causing leak memory issue.

The lifeCycleObserver is already remove itself once the lifeCycle is reached onDestroyed. But with activity, it will be never called until the activity is going on destroyed.

hoangthan avatar Jun 24 '23 10:06 hoangthan

Since the context is using ActivityLifeCycle. So trying to add lifeCycleObserver without remove when the view is being detached will causing leak memory issue.

The lifeCycleObserver is already remove itself once the lifeCycle is reached onDestroyed. But with activity, it will be never called until the activity is going on destroyed.

The behavior for this flow has now been revised and adjusted by re-evaluating the LifecycleOwner on attach. Do you still the leak on the latest version?

umberto-sonnino avatar Jul 19 '23 10:07 umberto-sonnino

Since the context is using ActivityLifeCycle. So trying to add lifeCycleObserver without remove when the view is being detached will causing leak memory issue. The lifeCycleObserver is already remove itself once the lifeCycle is reached onDestroyed. But with activity, it will be never called until the activity is going on destroyed.

The behavior for this flow has now been revised and adjusted by re-evaluating the LifecycleOwner on attach. Do you still the leak on the latest version?

Is 5.1.5 the latest version ?

stevezuju avatar Jul 20 '23 03:07 stevezuju

Since the context is using ActivityLifeCycle. So trying to add lifeCycleObserver without remove when the view is being detached will causing leak memory issue. The lifeCycleObserver is already remove itself once the lifeCycle is reached onDestroyed. But with activity, it will be never called until the activity is going on destroyed.

The behavior for this flow has now been revised and adjusted by re-evaluating the LifecycleOwner on attach. Do you still the leak on the latest version?

The life-cycler you're using is activity lifecycle. The observer will be never removed in case activity not going on destroyed. You should remove the observer while the RiveTextureView is going to detached.

stevezuju avatar Jul 20 '23 03:07 stevezuju

Since the context is using ActivityLifeCycle. So trying to add lifeCycleObserver without remove when the view is being detached will causing leak memory issue. The lifeCycleObserver is already remove itself once the lifeCycle is reached onDestroyed. But with activity, it will be never called until the activity is going on destroyed.

The behavior for this flow has now been revised and adjusted by re-evaluating the LifecycleOwner on attach. Do you still the leak on the latest version?

The life-cycler you're using is activity lifecycle. The observer will be never removed in case activity not going on destroyed. You should remove the observer while the RiveTextureView is going to detached.

The latest version is 6.0.0, is that what you're using? Changes were introduced here but we're not referencing the Activity directly.

umberto-sonnino avatar Jul 20 '23 15:07 umberto-sonnino