code: def add_periodic_callback(doc, component, interval):
      """Add periodic callback to doc in a way that avoids reference cycles
  
      If we instead use ``doc.add_periodic_callback(component.update, 100)`` then
      the component stays in memory as a reference cycle because its method is
      still around.  This way we avoid that and let things clean up a bit more
      nicely.
  
      TODO: we still have reference cycles.  Docs seem to be referred to by their
      add_periodic_callback methods.
      """
      ref = weakref.ref(component)
  
      doc.add_periodic_callback(lambda: update(ref), interval)
      _attach(doc, component)
  
file_path: distributed/distributed/dashboard/components/__init__.py
imports: from __future__ import annotations
  import weakref
  from bokeh.core.properties import without_property_validation
label_desc: Use image node_id 1 for calling a global function with example usage: add_periodic_callback(doc, component, interval) without return types