code: def assert_does_not_leak(
      f, iterations=10, check_interval=1, tolerance=5
  ):
      gc.collect()
      baseline = memory_profiler.memory_usage()[0]
      for i in range(iterations):
          f()
          if i % check_interval == 0:
              gc.collect()
              usage = memory_profiler.memory_usage()[0]
              diff = usage - baseline
              print("{0}: {1}\r".format(i, diff), end="")
              if diff > tolerance:
                  raise Exception(
                      "Memory increased by {0} megabytes after {1} "
                      "iterations".format(diff, i + 1)
                  )
      gc.collect()
      usage = memory_profiler.memory_usage()[0]
      diff = usage - baseline
      print(
          "\nMemory increased by {0} megabytes after {1} "
          "iterations".format(diff, iterations)
      )
  
file_path: arrow/python/scripts/test_leak.py
imports: import pyarrow
  import numpy
  import pandas
  from pyarrow.tests.util import rands
  import memory_profiler
  import gc
  import io
label_desc: Use image node_id 1 for calling a global function with example usage: assert_does_not_leak(f, iterations, check_interval, tolerance) without return types