TECHNOLOGY

Ray pending tasks: deleting a local reference may not release its object

In this article
THE QUICK TAKE

Distributed references, pending consumers and captured ObjectRefs can retain data beyond one local variable's lifetime; bound submission and inspect reference categories.

A driver submits work faster than workers finish, deletes its input variable, and still sees object-store pressure. Local deletion removed one reference, but queued consumers and other captured references remain. Diagnose retention before concluding that garbage collection or spilling is broken.

Name the retained object

Record ObjectRef identity, creation site, expected consumers and value size. Separate worker heap from shared object-store memory; summing process memory without its shared component can double-count the same value. The memory-management guide describes these categories and distributed reference counting. A local Python variable is only one possible holder. A completed producer does not imply its output is unneeded while pending or running consumers still depend on it.

Follow references beyond the driver

Inspect local references, arguments used by pending tasks and references captured inside other objects. Removing an outer variable does not necessarily remove every reachable nested holder. The documented ray memory output associates reference categories with processes and creation sites. Use those identities to find a retaining path rather than guessing from aggregate bytes. Distinguish retained data eligible for movement from buffers actively pinned by a worker’s direct shared-memory view.

Bound the submitting population

The pending-task pattern uses ray.wait to stop unbounded submission when producers outrun consumers. Maintain a deliberate in-flight set and process completed outcomes before extending it. This is different from limiting currently executing tasks through resource requests. The Serve queue-scope guide illustrates the adjacent topology problem: a local bound is meaningful only when the application knows how many independent submitters retain their own pending work.

Release outcomes after consuming them

An admission loop can still retain everything if it accumulates every completed reference or fetched result in a permanent list. Define when the application publishes, consumes and releases each output. Include exception paths that might retain batches for diagnostics. If durable output is required, use an explicit artifact boundary such as the revision publication protocol, then discard transient holders only after the application no longer needs them. Persistence and reference release are separate decisions.

Compare steady and growing populations

In a disposable workload, hold consumer speed fixed and compare unbounded submission with a declared in-flight bound. Observe pending count, reference categories, retained output collections and memory trends together. After consumers finish, inspect which holders remain. Acceptance is an explained bounded lifecycle, not a promise that every byte immediately returns to the operating system. This proposed observation protocol makes no claim about measured memory savings or a completed stress test.

Keep the diagnosis limited

A remaining reference can explain retention without proving every memory increase has that cause. Python heaps, framework allocators and runtime bookkeeping need separate evidence. Likewise, moving object values to disk does not remove their logical references. Record the retaining path and release condition with the fix. The supported conclusion is that the chosen workload stops accumulating unneeded pending work and completed results; it is not a cluster-wide memory ceiling or protection against arbitrary temporary allocations inside a task.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles