Skip to content

Commit

Permalink
[WinForms] Fix #137: memory leak in evaluate_js
Browse files Browse the repository at this point in the history
  • Loading branch information
shivaprsd committed Oct 18, 2017
1 parent 672d1b5 commit ab355cc
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion webview/winforms.py
Expand Up @@ -250,11 +250,14 @@ def _evaluate_js():
document = self.browser.web_browser.Document
script_element = document.CreateElement('script')
function_name = 'invoke' + uuid1().hex
code = 'function {0}() {{return eval("{1}")}}'.format(function_name, _escape_string(script))
code = 'function {0}() {{ {0} = null; return eval("{1}"); }}'
code = code.format(function_name, _escape_string(script))

script_element.InnerText = code
document.Body.AppendChild(script_element)
self._js_result = document.InvokeScript(function_name)
self._js_result_semaphor.release()
script_element.OuterHTML = ''

if self.browser.web_browser.InvokeRequired:
self.browser.web_browser.Invoke(Func[Type](_evaluate_js))
Expand Down

0 comments on commit ab355cc

Please sign in to comment.