code: def check_memory_released(
      exporter: CDataExporter, importer: CDataImporter
  ):
      """
      A context manager for memory release checks.
  
      The context manager arranges cooperation between the exporter and importer
      to try and release memory at the end of the enclosed block.
  
      However, if either the exporter or importer doesn't support deterministic
      memory release, no memory check is performed.
      """
      do_check = (
          exporter.supports_releasing_memory
          and importer.supports_releasing_memory
      )
      if do_check:
          before = exporter.record_allocation_state()
      yield
      # Only check for memory state if `yield` didn't raise.
      if do_check:
          for _ in _release_memory_steps(exporter, importer):
              after = exporter.record_allocation_state()
              if after == before:
                  break
          if after != before:
              raise RuntimeError(
                  f"Memory was not released correctly after roundtrip: "
                  f"before = {before}, after = {after} (should have been equal)"
              )
  
file_path: arrow/dev/archery/archery/integration/cdata.py
imports: import cffi
  from contextlib import contextmanager
  import functools
  import os
  import sys
  from .tester import CDataExporter, CDataImporter
label_desc: Use image node_id 3 for calling a global function with example usage: check_memory_released(exporter, importer) without return types