voyager icon indicating copy to clipboard operation
voyager copied to clipboard

fix activity leak after configuration change

Open shpasha opened this issue 1 year ago • 1 comments

ISSUE SOLVED: 112

Problem

During the configuration change process, the onDispose method in AndroidScreenLifecycleOwner is not called. As I understand it, this is normal, because almost all DisposableEffects in voyager ignore configuration changes.

But this leads to the fact that atomicContext.getAndSet(null) in onDispose is not executed and the activity leaks. The side effect of such a leak is that when the onDispose method in AndroidScreenLifecycleOwner is called, it will not work correctly, because this code if (activity != null && activity.isChangingConfigurations) return will complete the function execution because reference here for the old activity in which isChangingConfigurations is true

Solution

I simply add a callback to the lifecycle that resets the atomicContext field when activity is in onDestory state.

shpasha avatar May 16 '24 08:05 shpasha

If onDispose is not called when the configuration changes (or am i wrong?), maybe we can get rid of activity.isChangingConfigurations check, then get rid of the reference to the activity context and store a reference to the application context instead?

I was dive into the code this days and I also though about this.

DevSrSouza avatar May 18 '24 00:05 DevSrSouza