◐ Shell
clean mode source ↗

Message 253899 - Python tracker

The are is a reference loop:

    global instance -> type -> method -> module globals -> global instance

Since an instance doesn't have GC head if __slots__ is empty, the loop can't be broken.

A workaround is to add a stub element to __slots__:

    __slots__ = ('__stub__',)

But operator.subscript is not the only class that causes a reference leak. Any class with empty __slots__ can create a loop and cause a leak.