class_docstr: Keep track of and clean up after modules created while building Bokeh
  Documents.
docstr: Clean up any added modules, and check that there are no unexpected
  referrers afterwards.
  
  Returns:
      None
docstr_tok: ["Clean","up","any","added","modules",",","and","check","that","there","are","no","unexpected","referrers","afterwards",".","Returns",":","None"]
code: def destroy(self) -> None:
      """Clean up any added modules, and check that there are no unexpected
      referrers afterwards.
  
      Returns:
          None
  
      """
      from gc import get_referrers
      from types import FrameType
  
      log.debug(
          f"Deleting {len(self._modules)} modules for document {self._document()!r}"
      )
  
      for module in self._modules:
          # Modules created for a Document should have three referrers at this point:
          #
          # - sys.modules
          # - self._modules
          # - a frame object
          #
          # This function will take care of removing these expected references.
          #
          # If there are any additional referrers, this probably means the module will be
          # leaked. Here we perform a detailed check that the only referrers are expected
          # ones. Otherwise issue an error log message with details.
          referrers = get_referrers(module)
          referrers = [
              x for x in referrers if x is not sys.modules
          ]  # lgtm [py/comparison-using-is]
          referrers = [
              x for x in referrers if x is not self._modules
          ]  # lgtm [py/comparison-using-is]
          referrers = [
              x for x in referrers if not isinstance(x, FrameType)
          ]
          if len(referrers) != 0:
              log.error(
                  f"Module {module!r} has extra unexpected referrers! This could indicate a serious memory leak. Extra referrers: {referrers!r}"
              )
  
          # remove the reference from sys.modules
          if module.__name__ in sys.modules:
              del sys.modules[module.__name__]
  
          # explicitly clear the module contents and the module here itself
          module.__dict__.clear()
          del module
  
      # remove the references from self._modules
      self._modules = []
  
file_path: bokeh/src/bokeh/document/modules.py
imports: from __future__ import annotations
  import logging
  import sys
  import weakref
  from types import ModuleType
  from typing import TYPE_CHECKING
label_desc: Use image node_id 4 for calling the DocumentModuleManager obj's underlying member method code with example usage: obj.destroy() without return types