code: def check_memory(
      local_objs, num_spilled_objects=None, num_plasma_objects=None
  ):
      def ok():
          s = ray._private.internal_api.memory_summary()
          print(f"\n\nMemory Summary:\n{s}\n")
  
          actual_objs = re.findall(
              r"LOCAL_REFERENCE[\s|\|]+([0-9a-f]+)", s
          )
          if sorted(actual_objs) != sorted(local_objs):
              raise RuntimeError(
                  f"Expect local objects={local_objs}, actual={actual_objs}"
              )
  
          if num_spilled_objects is not None:
              m = re.search(r"Spilled (\d+) MiB, (\d+) objects", s)
              if m is not None:
                  actual_spilled_objects = int(m.group(2))
                  if actual_spilled_objects < num_spilled_objects:
                      raise RuntimeError(
                          f"Expected spilled objects={num_spilled_objects} "
                          f"greater than actual={actual_spilled_objects}"
                      )
  
          if num_plasma_objects is not None:
              m = re.search(
                  r"Plasma memory usage (\d+) MiB, (\d+) objects", s
              )
              if m is None:
                  raise RuntimeError(
                      "Memory summary does not contain Plasma memory objects count"
                  )
              actual_plasma_objects = int(m.group(2))
              if actual_plasma_objects != num_plasma_objects:
                  raise RuntimeError(
                      f"Expected plasma objects={num_plasma_objects} not equal "
                      f"to actual={actual_plasma_objects}"
                  )
  
          return True
  
      wait_for_condition(ok, timeout=30, retry_interval_ms=5000)
  
file_path: ray/python/ray/tests/test_autoscaler_fake_scaledown.py
imports: import platform
  import re
  import numpy
  import pytest
  import ray
  from ray._private.test_utils import wait_for_condition
  from ray.cluster_utils import AutoscalingCluster
label_desc: Use image node_id 2 for calling a global function with example usage: check_memory(local_objs, num_spilled_objects, num_plasma_objects) and returns: True