code: def _auto_weakref(function):
      """Create weakrefs to self (or other free vars in __closure__) then evaluate.
  
      When a nested function is defined within an instance method, and the function makes
      use of ``self``, it creates a reference cycle that the Python garbage collector is
      not smart enough to resolve, so the parent object is never GC'd. (The reference to
      ``self`` becomes part of the ``__closure__`` of the nested function).
  
      This decorator allows the nested function to access ``self`` without increasing the
      reference counter on ``self``, which will prevent the memory leak. If the referent
      is not found (usually because already GC'd) it will short-circuit the decorated
      function and return ``None``.
      """
      names = function.__code__.co_freevars
      assert len(names) == len(function.__closure__)
      __weakref_values__ = dict()
      evaldict = dict(__weakref_values__=__weakref_values__)
      for name, value in zip(names, function.__closure__):
          __weakref_values__[name] = weakref.ref(value.cell_contents)
      body = dedent(inspect.getsource(function))
      body = body.splitlines()
      for li, line in enumerate(body):
          if line.startswith(" "):
              body = body[li:]
              break
      old_body = "\n".join(body)
      body = """\
  def %(name)s(%(signature)s):
  """
      for name in names:
          body += f"""
      {name} = __weakref_values__[{repr(name)}]()
      if {name} is None:
          return
  """
      body = body + old_body
      fm = FunctionMaker(function)
      fun = fm.make(body, evaldict, addsource=True)
      fun.__globals__.update(function.__globals__)
      assert fun.__closure__ is None, fun.__closure__
      return fun
  
imports: import fnmatch
  import gc
  import hashlib
  import inspect
  import os
  import subprocess
  import sys
  import traceback
  import weakref
  from contextlib import ExitStack, contextmanager
  from importlib.resources import files
  from math import log
  from queue import Empty, Queue
  from string import Formatter
  from textwrap import dedent
  from threading import Thread
  import numpy
  from decorator import FunctionMaker
  from ._logging import logger, verbose, warn
  from .check import _check_option, _validate_type
label_desc: Use image node_id 17 for calling a global function with example usage: _auto_weakref(function) and returns: fun