jdxi_editor.ui.main_thread_gc

Python’s garbage collector runs on the main (Qt) thread only.

Left automatic, the collector runs in whichever thread happens to allocate when a generation is full: the MIDI request queue’s or a recording thread. Collecting a reference cycle that holds Qt objects there destroys them outside the main thread, and Qt crashes (a segmentation fault seen on macOS: “Garbage-collecting” in the request queue’s thread).

So automatic collection is turned off and the same thresholds are checked from the main thread: by a timer in the app (install), after each test in the tests (collect_if_due).

Attributes

INTERVAL_MS

Classes

MainThreadGC

Functions

collect_if_due() → int

Collect the generations whose counts passed their thresholds, as the

install(app) → MainThreadGC

Turn automatic collection off and collect from app's thread (call once,

Module Contents

jdxi_editor.ui.main_thread_gc.INTERVAL_MS = 500[source]
jdxi_editor.ui.main_thread_gc.collect_if_due() → int[source]

Collect the generations whose counts passed their thresholds, as the automatic collector would; returns the objects collected.

class jdxi_editor.ui.main_thread_gc.MainThreadGC(parent: PySide6.QtCore.QObject | None = None, interval_ms: int = INTERVAL_MS)[source]

Bases: PySide6.QtCore.QObject

timer[source]
jdxi_editor.ui.main_thread_gc.install(app: PySide6.QtCore.QObject) → MainThreadGC[source]

Turn automatic collection off and collect from app’s thread (call once, after creating the QApplication); the object lives as long as app.