Skip to content

Fix memory leak and zombie routers in clearTop navigation#1

Open
mhdamirhamza wants to merge 1 commit into
mainfrom
mhdamirhamza-patch-1
Open

Fix memory leak and zombie routers in clearTop navigation#1
mhdamirhamza wants to merge 1 commit into
mainfrom
mhdamirhamza-patch-1

Conversation

@mhdamirhamza

Copy link
Copy Markdown
Owner

Fixes a memory leak and zombie routers issue in StackRouterNavigator.kt during CLEAR_TOP navigation. Previously, intermediate stack entries were removed from the navigationStack iterator using navigationIterator.remove() without invoking detachInternal(). This caused those intermediate routers to remain active as zombie/live children of the host router, leaking views, interactors, and RxJava subscriptions in memory.

This contribution fixes the issue by explicitly calling detachInternal(routerAndState, newState, true) right before the iterator removes the state, ensuring proper lifecycle teardown.

Related issue(s):
None (Found via manual source code security audit).

Test plan:
Verified that the correct lifecycle teardown (willDetachFromHost and onPostDetachFromHost) triggers properly for all bypassed routers when CLEAR_TOP flag is executed.

Call detachInternal() on intermediate stack entries before removing them from the iterator in clearTop() to ensure correct lifecycle teardown and prevent memory leaks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant