Disable automatic garbage collection and instead collect manually every INTERVAL milliseconds.
This is done to ensure that garbage collection only happens in the GUI thread, as otherwise Qt can crash.
This code is serves as a workaround for a bug in PyQt:
and is modeled after the original code of Kovid Goyal