-
-
Notifications
You must be signed in to change notification settings - Fork 47
fix(android): Leaking listeners #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
fix(android): Leaking listeners #118
Conversation
private void setupMarkerListener() { | ||
ReactMarker.addListener( | ||
contentAppearedListener | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need a separate method for it :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we remove the other listener too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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,
ReactMarker
will know that this listener has already been added, so it won’t add it again, preventing duplication whenPerformancePackage
constructor is called multiple times). - We don’t need to remove it in
invalidate
because this listener isn’t bound to the native module’s lifetime.
Hi @oblador! Would you have some time to review this PR? 🙏 |
This PR fixes three leaks of listeners:
CONTENT_APPEARED
andRELOAD
to a constant to prevent leak when module is invalidated. Now we remove this listener ininvalidate
.RNPerformance.removeListener
had an incorrect condition that prevented listeners from being removed.getPackages
can be called multiple times in React Native, thePerformancePackage
constructor may also be invoked multiple times, resulting in several identical listeners being added as different instances.ReactMarker
prevents duplicates only when the same instance is added, so extracting the listener to a static constant resolves this issue.Additionally I changed
onCatalystInstanceDestroyed
toinvalidate
, because previous method is deprecated.