"""Measures FMOD Studio's private bytes (= Task Manager > Details > Commit size) before and after N evaluations on the scripting terminal (TCP 3663). Python 3, standard library only, Windows. Usage: python fmod_terminal_leak_repro.py [N] [expression] (defaults: 5000, "1")""" import ctypes, ctypes.wintypes as w, socket, subprocess, sys, time class PMC(ctypes.Structure): _fields_ = [("cb", w.DWORD), ("PageFaultCount", w.DWORD)] + [(n, ctypes.c_size_t) for n in ( "PeakWorkingSetSize", "WorkingSetSize", "QuotaPeakPagedPoolUsage", "QuotaPagedPoolUsage", "QuotaPeakNonPagedPoolUsage", "QuotaNonPagedPoolUsage", "PagefileUsage", "PeakPagefileUsage", "PrivateUsage")] def studio_pid(): out = subprocess.run(["tasklist", "/FI", "IMAGENAME eq FMOD Studio.exe", "/FO", "CSV", "/NH"], capture_output=True, text=True).stdout.strip().splitlines() pids = [int(l.split('","')[1]) for l in out if l.startswith('"FMOD')] if len(pids) != 1: sys.exit(f"expected one FMOD Studio.exe, found {len(pids)}") return pids[0] def private_mb(pid): h = ctypes.windll.kernel32.OpenProcess(0x1000, False, pid) # PROCESS_QUERY_LIMITED_INFORMATION c = PMC(); c.cb = ctypes.sizeof(c) ctypes.windll.psapi.GetProcessMemoryInfo(h, ctypes.byref(c), c.cb) ctypes.windll.kernel32.CloseHandle(h) return c.PrivateUsage / 2**20 n = int(sys.argv[1]) if len(sys.argv) > 1 else 5000 expr = (sys.argv[2] if len(sys.argv) > 2 else "1").encode() pid = studio_pid() before = private_mb(pid) s = socket.create_connection(("127.0.0.1", 3663)) def read_frame(): buf = b"" while not buf.endswith(b"\x00"): buf += s.recv(65536) return buf read_frame() # greeting for _ in range(n): s.sendall(expr) read_frame() s.close() time.sleep(2) after = private_mb(pid) print(f"{n} evaluations of {expr.decode()!r}: {before:.0f} MB -> {after:.0f} MB " f"(+{after - before:.1f} MB, {(after - before) * 1024 / n:.1f} KB per evaluation)")