Have stumbled onto this answer. Quoting comment in QT sources:
Dead resources in the cache are kept in non-purgeable memory.
When we prune dead resources, instead of freeing them, we mark their memory as purgeable and keep the resources until the kernel reclaims the purgeable memory.
By leaving the in-cache dead resources in dirty resident memory, we decrease the likelihood of the kernel claiming that memory and forcing us to refetch the resource (for example when a user presses back).
This sort of settles it.. and relives my restless soul.
Following bms20's advice I run QtWebKit
code in a separate process (using subprocess.Popen
) and cache web resources on disk (PyQt5.QtNetwork.QNetworkDiskCache
) to preserve traffic:
def ExecuteCode(code):
import os
os.environ['PYTHONIOENCODING'] = 'utf-8' #Optionally
from subprocess import Popen, PIPE, STDOUT
proc = Popen('python.exe', stdin=PIPE)
out, err = proc.communicate(code.encode())
Part of code
content:
cache = QNetworkDiskCache()
cache.setCacheDirectory('cache')
web_view = QWebView()
web_view.page().networkAccessManager().setCache(cache)
# Do stuff with web_page