fix(android): Leaking listeners#118
Merged
oblador merged 8 commits intooblador:masterfrom Oct 23, 2025
Merged
Conversation
war-in
approved these changes
Oct 1, 2025
4 tasks
war-in
reviewed
Oct 13, 2025
Comment on lines
+90
to
+94
| private void setupMarkerListener() { | ||
| ReactMarker.addListener( | ||
| contentAppearedListener | ||
| ); | ||
| } |
Contributor
There was a problem hiding this comment.
I don't think we need a separate method for it :)
Contributor
Author
There was a problem hiding this comment.
Right, I wanted to make this look similar to setupNativeMarkerListener which was already in the codebase
| // Fix new arch runtime error | ||
| public void addListener(String eventName) { | ||
|
|
||
| ReactMarker.removeListener(contentAppearedListener); |
Contributor
There was a problem hiding this comment.
Shouldn't we remove the other listener too?
Contributor
Author
There was a problem hiding this comment.
startupMarkerListener is specific, because once we add it to ReactMarker (singleton) it can stay there through the whole app lifetime.
I.e.:
- We add it once (by storing it in a static constant,
ReactMarkerwill know that this listener has already been added, so it won’t add it again, preventing duplication whenPerformancePackageconstructor is called multiple times). - We don’t need to remove it in
invalidatebecause this listener isn’t bound to the native module’s lifetime.
war-in
approved these changes
Oct 13, 2025
Contributor
Author
|
Hi @oblador! Would you have some time to review this PR? 🙏 |
oblador
approved these changes
Oct 23, 2025
Owner
oblador
left a comment
There was a problem hiding this comment.
I had been avoiding migrating to invalidate to keep bw compatibility, but since it's been there since 0.74 I think it should be fine to drop it now.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes three leaks of listeners:
CONTENT_APPEAREDandRELOADto a constant to prevent leak when module is invalidated. Now we remove this listener ininvalidate.RNPerformance.removeListenerhad an incorrect condition that prevented listeners from being removed.getPackagescan be called multiple times in React Native, thePerformancePackageconstructor may also be invoked multiple times, resulting in several identical listeners being added as different instances.ReactMarkerprevents duplicates only when the same instance is added, so extracting the listener to a static constant resolves this issue.Additionally I changed
onCatalystInstanceDestroyedtoinvalidate, because previous method is deprecated.