code: def _on_session_destroyed(session_context: SessionContext) -> None:
      """
      Calls any on_session_destroyed callbacks defined on the Document
      """
      callbacks = session_context._document.session_destroyed_callbacks
      session_context._document.session_destroyed_callbacks = set()
      for callback in callbacks:
          try:
              callback(session_context)
          except Exception as e:
              log.warning(
                  "DocumentLifeCycleHandler on_session_destroyed "
                  f"callback {callback} failed with following error: {e}"
              )
      if callbacks:
          # If any session callbacks were defined garbage collect after deleting all references
          del callback
          del callbacks
  
          import gc
  
          gc.collect()
  
file_path: bokeh/src/bokeh/application/handlers/document_lifecycle.py
imports: from __future__ import annotations
  import logging
  from ..application import SessionContext
  from .lifecycle import LifecycleHandler
label_desc: Use image node_id 1 for calling a global function with example usage: _on_session_destroyed(session_context) without return types