docstr: Initialize object resources that need to be cleaned up automatically.
docstr_tok: ["Initialize","object","resources","that","need","to","be","cleaned","up","automatically","."]
code: def __init__(self, instance: T) -> None:
      """
      Initialize object resources that need to be cleaned up automatically.
      """
      self.finalizer = weakref.finalize(instance, self._close)
      # We do not finalizer to automatically close the object itself.
      # Instead, we will collect all finalizers and call them at exit.
      self.finalizer.atexit = False
      self._finalizers[instance] = (self.PRIORITY, self.finalizer)
  
      if not AutoClean._registered_with_atexit:
          atexit.register(AutoClean.cleanup)
          AutoClean._registered_with_atexit = True
  
file_path: aim/aim/ext/cleanup/__init__.py
imports: import time
  from abc import abstractmethod
  import atexit
  import weakref
  import logging
  import threading
  from typing import Generic, Tuple, TypeVar, Dict
label_desc: Use image node_id 1 to create a new AutoClean object from inherited base classes: Generic with example: obj = AutoClean(instance)