Skip to content

Commit 12cafe1

Browse files
author
Alan
committed
Merge branch 'weakref' into combine_v1
2 parents b22a726 + 3541511 commit 12cafe1

File tree

1 file changed

+8
-6
lines changed
  • python/ipywidgets/ipywidgets/widgets

1 file changed

+8
-6
lines changed

python/ipywidgets/ipywidgets/widgets/widget.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

4749
def 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

5861
def 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

Comments
 (0)