{"record":{"id":"20887f5ae2102081","repo":"jax-ml/jax","slug":"tracer-leak-debugger-warning","errorCode":null,"errorMessage":"TRACER_LEAK_DEBUGGER_WARNING","messagePattern":"TRACER_LEAK_DEBUGGER_WARNING","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"jax/_src/core.py","lineNumber":1618,"sourceCode":"@contextmanager\ndef ensure_no_leaks(trace:Trace):\n  yield\n  trace.invalidate()\n  if config.check_tracer_leaks.value:\n    trace_ref = trace._weakref\n    del trace\n    live_trace = trace_ref()\n    if live_trace is not None:\n      leaked_tracers = maybe_find_leaked_tracers(live_trace)\n      if leaked_tracers:\n        raise leaked_tracer_error(\"trace\", live_trace, leaked_tracers)\n\n\ndef maybe_find_leaked_tracers(trace: Trace) -> list[Tracer]:\n  \"\"\"Find the leaked tracers holding a reference to the Trace\n  \"\"\"\n  if not getattr(threading.current_thread(), 'pydev_do_not_trace', True):\n    warnings.warn(TRACER_LEAK_DEBUGGER_WARNING)\n  # Trigger garbage collection to filter out unreachable objects that are alive\n  # only due to cyclical dependencies. (We don't care about unreachable leaked\n  # tracers since they can't interact with user code and cause a problem.)\n  gc.collect()\n  tracers = list(filter(lambda x: isinstance(x, Tracer), gc.get_referrers(trace)))\n  return tracers\n\ndef leaked_tracer_error(name: str, t, tracers: list[Tracer]) -> Exception:\n  assert tracers\n  why = partial(_why_alive, {id(tracers)})\n  msgs = []\n  for tracer in tracers:  # not a genexpr: it'd be gc-visible and self-report\n    chain = why(tracer)\n    label = f'<{type(tracer).__name__} {id(tracer)}>'\n    chain += ''.join(f'\\n{label} is referred to by {h}' for h in\n                     _held_in_frame_locals(tracer, {id(tracers)}))\n    if not chain:\n      chain = (f'\\n{label} has no referrers visible to the gc module; it may '","sourceCodeStart":1600,"sourceCodeEnd":1636,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/core.py#L1600-L1636","documentation":"JAX detected leaked tracers (JAX's intermediate values during tracing) and, because the current thread is being traced by a Python debugger (pydev), it warns that the debugger itself may be responsible. Debuggers keep frame references alive, which keeps Tracer objects from being garbage collected, producing false-positive leak reports.","triggerScenarios":"Running under a debugger (PyCharm/VSCode via pydev/pydevd) with JAX tracing that yields leaked-tracer diagnostics; maybe_find_leaked_tracers fires and sees pydev_do_not_trace is falsy on the thread, meaning the debugger is active.","commonSituations":"Debugging a jitted function in PyCharm or VSCode; breakpoints holding references to tracer values; check_leaks tests failing only when a debugger is attached.","solutions":["Ignore the warning if it appears only while a debugger is attached — rerun without the debugger to confirm.","Remove breakpoints that capture intermediate Tracer values, or del tracer references before leaving the function.","If leaks persist without a debugger, find where the Tracer escapes (e.g. stored in a global/attribute) and remove the retention."],"exampleFix":"# before\nglobal _cache\n_cache = x  # x is a Tracer leaked out of a jitted trace\n# after\n# don't retain tracers; materialize first\n_cache = jax.device_put(x) if outside trace else None","handlingStrategy":"validation","validationCode":"import threading\nrunning_under_debugger = not getattr(threading.current_thread(), 'pydev_do_not_trace', True)","typeGuard":null,"tryCatchPattern":"with warnings.catch_warnings():\n    warnings.filterwarnings('ignore', message='.*TRACER LEAK.*')\n    fn()  # during debugged runs","preventionTips":["Don't store Tracer values in globals/attributes; convert with .block_until_ready() or device_put first.","Re-run leak checks without a debugger attached before treating leaks as real.","Delete references to intermediates before returning from jitted/traced code."],"tags":["jax","tracer-leak","debugging","memory"],"backgroundTag":"resource-leak-warning","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}