code: def test_replica_memory_growth(serve_instance):
      # https://github.com/ray-project/ray/issues/12395
      @serve.deployment
      def gc_unreachable_objects(*args):
          gc.set_debug(gc.DEBUG_SAVEALL)
          gc.collect()
          gc_garbage_len = len(gc.garbage)
          if gc_garbage_len > 0:
              print(gc.garbage)
          return gc_garbage_len
  
      handle = serve.run(gc_unreachable_objects.bind())
  
      def get_gc_garbage_len_http():
          result = requests.get("http://127.0.0.1:8000")
          assert result.status_code == 200
          return result.json()
  
      # We are checking that there's constant number of object in gc.
      known_num_objects_from_http = get_gc_garbage_len_http()
  
      for _ in range(10):
          assert (
              get_gc_garbage_len_http() == known_num_objects_from_http
          )
  
      known_num_objects_from_handle = handle.remote().result()
      for _ in range(10):
          assert (
              handle.remote().result() == known_num_objects_from_handle
          )
  
imports: import asyncio
  import gc
  import sys
  import numpy
  import pytest
  import requests
  from fastapi import FastAPI
  from fastapi.responses import JSONResponse
  import ray
  from ray import serve
  from ray._private.test_utils import SignalActor
  from ray.serve.context import _get_global_client
  from ray.serve.handle import DeploymentHandle
label_desc: Use image node_id 4 for calling a global function with example usage: test_replica_memory_growth(serve_instance) and returns: gc_garbage_len, result