question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Memory leak on windows

See original GitHub issue

There 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:closed
  • Created 6 years ago
  • Comments:26 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
pomplesiegelcommented, Oct 20, 2017

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?

1reaction
r0x0rcommented, Oct 20, 2017

Here is what I found out.

  1. As it was pointed above, your original program has got an infinite loop. Remember that create_window blocks execution, until the window is destroyed
  2. I have modified the script to invoke doNothing repeatedly without invoking evaluate_js and memory grows in the same fashion as with evaluate_js. Furthermore IE does the same.
<!DOCTYPE html>
<html>
<script type="text/javascript">
	function doNothing() { }

	for(var i =0; i < 100000; i++) {
	    doNothing();
    }
</script>
<head>
</head>
<body>
<div>
    <button onclick="doNothing()">Test</button>
</div>
</body>
</html>
  1. All in all, it seems this is how IE garbage collection works and there is nothing we can do about that. A good thing that we got rid script elements and invoke functions, though!
Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Fix Windows 10 Memory Leaks - Online Tech Tips
A Windows 10 memory leak occurs when an app you were using didn't return the resources to your system when you finished using...
Read more >
How to Fix A Windows Memory Leak - Lifewire
Find a Memory Leak With Windows' Resource Monitor · Press Windows key+R, enter "resmon," then select OK.
Read more >
Fix a Memory Leak on Windows 10 with These 7 Methods
How can I fix a memory leak in Windows 10? · 1. End specific processes · 2. Use the Windows 10 built-in tools...
Read more >
Memory leaks in Windows 10/11 - Stellar Data Recovery
A memory leak results from incorrect memory management when a program fails to release the memory they no longer need so that some...
Read more >
How do I check for memory leaks, and what should I do to stop ...
To find a memory leak, you've got to look at the system's RAM usage. This can be accomplished in Windows by using the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found