code: def test_weakref_leak():
      """Check that the rewrite does not have a growing memory footprint.
  
      See #6990
      """
  
      def _growth(limit=10, peak_stats={}):
          """Vendoring of objgraph.growth
  
          Source: https://github.com/mgedmin/objgraph/blob/94b1ca61a11109547442701800292dcfc7f59fc8/objgraph.py#L253
          """
          gc.collect()
          objects = gc.get_objects()
  
          stats = {}
          for o in objects:
              n = type(o).__name__
              stats[n] = stats.get(n, 0) + 1
  
          deltas = {}
          for name, count in stats.items():
              old_count = peak_stats.get(name, 0)
              if count > old_count:
                  deltas[name] = count - old_count
                  peak_stats[name] = count
  
          deltas = sorted(
              deltas.items(), key=operator.itemgetter(1), reverse=True
          )
  
          if limit:
              deltas = deltas[:limit]
  
          return [(name, stats[name], delta) for name, delta in deltas]
  
      rvs_to_values = {
          pt.random.beta(1, 1, name=f"p_{i}"): pt.scalar(f"p_{i}")
          for i in range(30)
      }
      tr = TransformValuesRewrite(
          {v: logodds for v in rvs_to_values.values()}
      )
  
      for i in range(20):
          conditional_logp(rvs_to_values, extra_rewrites=tr)
          res = _growth()
          # Only start checking after warmup
          if i > 15:
              assert not res, "Object counts are still growing"
  
imports: import gc
  import operator
  import numpy
  import pytensor
  import pytest
  import scipy
  from numdifftools import Jacobian
  from pytensor import scan
  from pytensor import tensor
  from pytensor.compile.builders import OpFromGraph
  from pytensor.graph import FunctionGraph
  from pytensor.graph.basic import equal_computations
  import pymc
  from pymc.distributions.transforms import _default_transform, log, logodds
  from pymc.logprob import conditional_logp
  from pymc.logprob.abstract import MeasurableVariable, _logprob
  from pymc.logprob.transform_value import TransformValuesMapping, TransformValuesRewrite
  from pymc.logprob.transforms import ExpTransform, LogOddsTransform, LogTransform
  from pymc.testing import assert_no_rvs
  from tests.logprob.test_transforms import DirichletScipyDist
label_desc: Use image node_id 13 for calling a global function with example usage: test_weakref_leak() and returns: unknown