Open
Description
Hello!
We integrated Adjust WebBridge and after some tests noticed, that this class causes a memory leak.
What do we do?
- For example, we have
WebPageView: UIView
, that contains propertylet webView = WKWebView()
- Also, we added property
let adjustBridge: AdjustBridge = AdjustBridge()
inWebPageView
- Next, we overried
init()
method ofWebPageView
and addedadjustBridge.loadWKWebViewBridge(webView)
- After this, we tested, that Adjust WebBridge JS interface works correctly and we can see our events using testing console.
What goes wrong?
When we close the instance of WebPageView
, we can see that WKWebView is still present in memory.
What causes the memory leak
Fortunately, AdjustWebBridge is an open-source framework and we can see the implementation. So, during the AdjustBridge initialization, framework:
- Stores the strong reference to our WKWebView instance.
- Calls method
addScriptMessageHandler
and pass self (instance of AdjustBridge) as a parameter. Note, that addScriptMessageHandler adds the strong reference of AdjustBridge to our WKWebView - After this, we have the retain cycle: AdjustBridge -> WKWebView -> (private property) scriptMessagehandlersArray -> AdjustBridge
How can you fix this
The most simple way to do this - make webView
propery in AdjustBridge weak.
Metadata
Metadata
Assignees
Labels
No labels