class_docstr: Generically tests our memory leak diagnostics tools.
class_docstr_tok: ["Generically","tests","our","memory","leak","diagnostics","tools","."]
docstr: Tests, whether our diagnostics tools can detect leaks in a policy.
docstr_tok: ["Tests",",","whether","our","diagnostics","tools","can","detect","leaks","in","a","policy","."]
code: def test_leaky_policy(self):
      """Tests, whether our diagnostics tools can detect leaks in a policy."""
  
      # if the leak is small you need more repeats to catch it. So we intentionally
      # increase the leakage size to make it easier to catch with fewer repeats.
      config = (
          dqn.DQNConfig()
          .environment("CartPole-v1")
          # Make sure we have an env to test on the local worker.
          # Otherwise, `check_memory_leaks` will complain.
          .rollouts(create_env_on_local_worker=True)
          .multi_agent(
              policies={
                  "default_policy": PolicySpec(
                      policy_class=MemoryLeakingPolicy,
                      config={"leakage_size": "large"},
                  ),
              }
          )
      )
      algo = config.build()
      results = check_memory_leaks(
          algo, to_check={"policy"}, repeats=10
      )
      assert results["policy"]
      algo.stop()
  
file_path: ray/rllib/algorithms/tests/test_memory_leaks.py
imports: import unittest
  import ray
  import ray.rllib.algorithms.dqn
  import ray.rllib.algorithms.ppo
  from ray.rllib.examples.env.memory_leaking_env import MemoryLeakingEnv
  from ray.rllib.examples.policy.memory_leaking_policy import MemoryLeakingPolicy
  from ray.rllib.policy.policy import PolicySpec
  from ray.rllib.utils.debug.memory import check_memory_leaks
label_desc: Use image node_id 4 for calling the TestMemoryLeaks obj's underlying member method code with example usage: obj.test_leaky_policy() without return types