Skip to content
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

RUMM-1931 stopTrackingDatadogEvents added to avoid memory leaks #745

Merged
merged 2 commits into from
Feb 8, 2022

Conversation

buranmert
Copy link
Contributor

What and why?

Without removing WKScriptMessageHandlers explicitly, they stay alive in memory even after deallocation of the webview

How?

By calling stopTrackingDatadogEvents, our users can remove Datadog components from their WKWebViewConfiguration instances so that DatadogMessageHandler can be deallocated.

Review checklist

  • Feature or bugfix MUST have appropriate tests (unit, integration)
  • Make sure each commit and the PR mention the Issue number or JIRA reference

Without removing ScriptMessageHandlers explicitly, they stay alive in memory
even after deallocation of the webview
@buranmert buranmert self-assigned this Feb 3, 2022
@buranmert buranmert requested a review from a team as a code owner February 3, 2022 13:57
Copy link
Member

@maxep maxep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I've minor suggestions tho

/// Disables Datadog iOS SDK and Datadog Browser SDK integration.
///
/// Removes Datadog's ScriptMessageHandler and UserScript from the caller.
/// _NOTE:_ This method **must** be called when the webview can be deinitialized.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't render properly, better to use

Suggested change
/// _NOTE:_ This method **must** be called when the webview can be deinitialized.
/// - Note: This method **must** be called when the webview can be deinitialized.

Comment on lines 27 to 29
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
return
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/nit

Suggested change
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
return
}
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) { }


controller.trackDatadogEvents(in: [])

let componentCount = 10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why make it 10? I guess adding a single or a couple of other scripts will cover this change

Copy link
Member

@ncreated ncreated left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 It would be also good to add stopTrackingDatadogEvents() in "Webviews integration" screen in Example app. Otherwise we don't have any use of this API outside unit tests.

@buranmert buranmert force-pushed the buranmert/RUMM-1931-stopTrackingWebEvents branch from c43e372 to deb2ddd Compare February 8, 2022 14:24
@buranmert buranmert merged commit 6eb728e into master Feb 8, 2022
@buranmert buranmert deleted the buranmert/RUMM-1931-stopTrackingWebEvents branch February 8, 2022 15:10
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.

3 participants