@@ -41,13 +41,16 @@ def envset(name, default):
4141# for a discussion on using weak references see:
4242# https://github.com/jupyter-widgets/ipywidgets/issues/1345
4343
44+ # A global to store all widget instances so that it can be swapped out when
45+ # enabling/disabling weakreferences
4446_widget_instances = {}
4547
4648
4749def enable_weakreference ():
48- """Use a WeakValueDictionary to store references to Widget instances .
50+ """Configure the module to only maintain a weakreference between the comm_id and widget for all widgets .
4951
50- A strong reference must be kept to widgets.
52+ With this enabled the user must maintain a strong reference to widgets. The
53+ advantage being that memory leaks prevented in long running programs.
5154 """
5255 global _widget_instances
5356 if not isinstance (_widget_instances , weakref .WeakValueDictionary ):
@@ -56,11 +59,10 @@ def enable_weakreference():
5659
5760
5861def disable_weakreference ():
59- """Use a standard dictionary to store references to Widget instances (default behavior) .
62+ """Configure the module to only maintain a strong reference between the comm_id and widget for all widgets .
6063
61- Note: this is the default setting and maintains a strong reference to the
62- the widget preventing automatic garbage collection. When the widget is closed
63- it can be garbage collected.
64+ !!! Note:
65+ This is the default behavior. The method `Widget.close` should be called when it is no longer required.
6466 """
6567 global _widget_instances
6668 if isinstance (_widget_instances , weakref .WeakValueDictionary ):
0 commit comments