Memory leak on windows
See original GitHub issueThere appears to be a memory leak on Windows, occurring whenever webview.evaluate_js()
is called. I’m using pywebview v1.7 + “pythonnet” on Windows 10 64bit, with python3.6.2. The same issue does not exist on mac.
Code to reproduce (most trivial example I could come up with)
import webview
import threading
import time
threadStopSignal = threading.Event()
threadStopSignal.clear()
def checkOnDOM():
global threadStopSignal
while threadStopSignal.is_set() == False:
time.sleep(.01)
webview.evaluate_js("doNothing()" )
def main():
print("Beginning program")
t = threading.Thread(target=checkOnDOM)
t.start()
webview.create_window("This is a window", "index.html")
threadStopSignal.set()
t.join(3.0)
main()
<!DOCTYPE html>
<html>
<script type="text/javascript">
function doNothing() { }
</script>
<head>
</head>
<body>
<div>
</div>
</body>
</html>
Then watch the memory usage of the program grow in the task manager. The memory usage on Mac remains static when running this program.
In order to further investigate, I later changed doNothing to
function doNothing() {
return document.getElementsByTagName("script").length;
}
which, when printed in python, made it clear that the number of script elements is growing (and never shrinking) with each call to evaluate_js()
. Not sure if that’s the expected behavior.
Finally, if the value of those script tags is printed, we see something like
function invokecb2c8066aea211e7849010f0050b27cc() {return eval("doNothing()")}
which over time monotonically grows to higher values
function invokef9d07746aea211e780ee10f0050b27cc() {return eval("doNothing()")}
function invokef9d29312aea211e791b410f0050b27cc() {return eval("doNothing()")}
function invokef9d46ef6aea211e78f1f10f0050b27cc() {return eval("doNothing()")}
up and up… Are these pointers to resources in windows that never get cleaned up, or are they just GUIDs?
Happy to provide any more info.
Really enjoying the library, btw! Hoping to resolve the memory issue on the windows side so I can use it further.
Issue Analytics
- State:
- Created 6 years ago
- Comments:26 (9 by maintainers)
Top GitHub Comments
Great, thanks for looking into this. I’m happy with this as a result - was just trying to be thorough. Shall we consider this closed?
Here is what I found out.