How to release memory when wkwebview is closed

Viewed 176

the code is there the WKWebview memory demo

I am working on a keyboard extension project and need integrate WKWebview . but when I close the WKWebview, the memory is not released,

open webview

Close the webview and memory not release

I want the system or webview release the memory immediately,because the keyboard extension only have 66m memory limit.

Here is the code I try to solve this issue:

  URLCache.shared.removeAllCachedResponses()
  URLCache.shared.diskCapacity = 0
  URLCache.shared.memoryCapacity = 0

 //set WKWebViewConfiguration
  config.websiteDataStore = WKWebsiteDataStore.nonPersistent()

 //deinit
deinit {
        webView.uiDelegate = nil
        webView.navigationDelegate = nil
        webView.removeObserver(self, forKeyPath: "estimatedProgress")
       webView.configuration.userContentController.removeAllUserScripts()
       
    }
0 Answers
Related