How to stop WKWebView from creating too many processes?

一世执手 提交于 2019-12-11 01:58:41

问题


I have a MacOS app that creates many NSViews of differing types, some of which contain WKWebViews. The Number of WKWebViews can become fairly large (dozens or more).

The problem is that each of these WKWebViews creates several processes, as can be easily seen in Activity Monitor. When the number of processes becomes too large, the entire system essentially grinds to a halt: running apps still function slowly, but new apps can't be launched, the Finder stops working, and the system must be rebooted.

So I am looking for a way to control the number of processes started by WKWebViews.

According to Apple docs, this is managed by the processPool property of WKWebView, as they state: "The process pool associated with a web view is specified by its web view configuration. Each web view is given its own Web Content process until an implementation-defined process limit is reached; after that, web views with the same process pool end up sharing Web Content processes." (from the page at: https://developer.apple.com/documentation/webkit/wkprocesspool?language=objc).

I cannot figure out how to define that "implementation-defined process limit". When I NSLog the description of the WKWebView's configuration, I get this:

WKWebView configuration description:

>; preferences = >

I can see there's a processPool and a configuration for it (called _WKProcessPoolConfiguration), and a value called maximumProcessCount, which is set to 0. I am assuming that 0 means that the process count is unlimited, and I would like to set it to a reasonable number. But I cannot figure out how to set this value! The processPool itself has no properties, so I have no idea how to access this maximumProcessCount value.

Any help is greatly appreciated.


回答1:


  1. you can use singleton WKProcessPool and all wkwebview.configuration.processpool use that WKProcessPool singleton;

  2. it will resolve cpu too high.



来源:https://stackoverflow.com/questions/51886467/how-to-stop-wkwebview-from-creating-too-many-processes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!