pupil-labs / pyglui

cython powered OpenGL gui that works with glfw
MIT License
29 stars 20 forks source link

Make Use of Weak References #103

Open ckbaumann opened 5 years ago

ckbaumann commented 5 years ago

Controls like text boxes, sliders, and others often introduce cyclic references. For example, a plugin might have a property that is changed by a slider element. On one hand, this plugin will store a reference to the slider (e.g. in its menu). On the other hand, the slider stores a reference to the plugin s.t. it is able to change the value.

Such cycles should be detected during garbage collection, so the objects should get deleted anyway. However, performance might suffer (see this stack exchange)

Breaking this cycle would be possible by using weakref.

However, we should make sure that all objects then referenced weakly are still referenced somewhere else. Intuitively, this should be the case: If you don't reference the object elsewhere you can't read its value and it would be pointless to change it in a UI. Still, we should handle the case properly that weakly referenced objects become None.