Skip to content
This repository was archived by the owner on Feb 27, 2025. It is now read-only.

Commit 2d6227f

Browse files
Use with x.get_frame instead of x.get_frame globally
This should help prevent some minor memory leaks. Since it only happens upon init, the memory leaks ultimately shouldn't get worse over time (unless called in i.e. a frame eval). However, since a lot of functions call `get_prop`, this might negatively impact memory for scripts that depend on a lot of these functions.
1 parent d71fb67 commit 2d6227f

File tree

7 files changed

+18
-11
lines changed

7 files changed

+18
-11
lines changed

vstools/enums/other.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ def from_clip(cls: type[SarSelf], clip: HoldsPropValueT) -> SarSelf:
174174
if isinstance(clip, vs.RawFrame):
175175
props = clip.props
176176
elif isinstance(clip, vs.RawNode):
177-
props = clip.get_frame(0).props
177+
with clip.get_frame(0) as frame:
178+
props = frame.props
178179
else:
179180
props = clip
180181

vstools/exceptions/color.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ def check(func: FuncExceptT, to_check: vs.VideoNode) -> None:
6060
"""
6161

6262
try:
63-
to_check.get_frame(0)
63+
with to_check.get_frame(0):
64+
pass
6465
except vs.Error as e:
6566
if 'no path between colorspaces' in str(e):
6667
raise InvalidColorspacePathError(func, e)

vstools/functions/heuristics.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ def video_heuristics(
5959
heuristics = dict[str, PropEnum]()
6060

6161
if props is True:
62-
props_dict = clip.get_frame(0).props
62+
with clip.get_frame(0) as frame:
63+
props_dict = frame.props
6364
else:
6465
props_dict = props or None
6566

vstools/utils/info.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ def get_var_infos(frame: vs.VideoNode | vs.VideoFrame) -> tuple[vs.VideoFormat,
3030
if isinstance(frame, vs.VideoNode) and not (
3131
frame.width and frame.height and frame.format
3232
):
33-
frame = frame.get_frame(0)
33+
with frame.get_frame(0) as frame:
34+
pass
3435

3536
assert frame.format
3637

vstools/utils/misc.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ def match_clip(
8585
clip = clip.resize.Bicubic(format=ref.format.id, matrix=Matrix.from_video(ref))
8686

8787
if matrices:
88-
ref_frame = ref.get_frame(0)
89-
clip = clip.std.SetFrameProps(
90-
_Matrix=Matrix(ref_frame), _Transfer=Transfer(ref_frame), _Primaries=Primaries(ref_frame)
91-
)
88+
with ref.get_frame(0) as ref_frame:
89+
clip = clip.std.SetFrameProps(
90+
_Matrix=Matrix(ref_frame), _Transfer=Transfer(ref_frame), _Primaries=Primaries(ref_frame)
91+
)
9292

9393
return clip.std.AssumeFPS(fpsnum=ref.fps.numerator, fpsden=ref.fps.denominator)
9494

vstools/utils/props.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ def get_prop(
7878
if isinstance(obj, vs.RawFrame):
7979
props = obj.props
8080
elif isinstance(obj, vs.RawNode):
81-
props = obj.get_frame(0).props
81+
with obj.get_frame(0) as frame:
82+
props = frame.props
8283
else:
8384
props = obj
8485

vstools/utils/vs_proxy.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,12 @@ def clear_cache() -> None:
169169
try:
170170
for output in get_outputs().values():
171171
if isinstance(output, VideoOutputTuple):
172-
output.clip.get_frame(0)
172+
with output.clip.get_frame(0):
173+
pass
173174
break
174175
except Exception:
175-
core.std.BlankClip().get_frame(0)
176+
with core.std.BlankClip().get_frame(0):
177+
pass
176178
core.max_cache_size = cache_size
177179
except Exception:
178180
...

0 commit comments

Comments
 (0)