Skip to content

Commit

Permalink
Try to fix memory leak on reload
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuevo009 authored and AkarinVS committed Nov 23, 2022
1 parent 06b408c commit 2e784d4
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions vspreview/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
from pathlib import Path
import sys
from typing import Any, cast, List, Mapping, Optional, Union
from typing import Any, cast, List, Mapping, Optional, Union, Dict

from PyQt5 import Qt
import vapoursynth as vs
Expand Down Expand Up @@ -391,7 +391,7 @@ def __init__(self, config_dir: Path) -> None:
self.setWindowTitle('VSPreview')
self.move(400, 0)
self.setup_ui()

self.script_globals: Dict[str, Any] = dict()
# global

self.clipboard = self.app.clipboard()
Expand Down Expand Up @@ -510,11 +510,15 @@ def load_script(self, script_path: Path, external_args: List[tuple[str, str]] =
self.external_args = external_args
argv_orig = sys.argv
sys.argv = [script_path.name]
self.script_globals.clear()
self.script_globals = dict([('__file__', sys.argv[0])] + self.external_args)

ast_compiled = compile(
self.script_path.read_text(encoding='utf-8'), sys.argv[0], 'exec', optimize=2
)
try:
# pylint: disable=exec-used
exec(self.script_path.read_text(encoding='utf-8'),
dict([('__file__', sys.argv[0])] + self.external_args))
exec(ast_compiled, self.script_globals)
except Exception as e: # pylint: disable=broad-except
self.script_exec_failed = True
logging.error(e)
Expand Down

0 comments on commit 2e784d4

Please sign in to comment.