Certainly! Using named actors as a centralized reference manager means you create a long-lived, named actor (e.g., “PlasmaStoreActor”) whose sole responsibility is to store and manage all ObjectRefs that need to persist across tasks, actors, or deployments. Instead of passing ObjectRefs directly between tasks/actors (which can lead to lost references if an intermediate dies), you store all ObjectRefs in this actor and have all consumers retrieve the data via remote calls to the actor. This ensures the actor always holds a strong reference, preventing premature deletion, and provides a single place to manage object lifetimes and cleanup (see discussion, reference counting test).
Example pattern:
@ray.remote
class PlasmaStoreActor:
def __init__(self):
self.refs = {}
def put(self, key, data):
self.refs[key] = ray.put(data)
def get(self, key):
return ray.get(self.refs[key])
def delete(self, key):
del self.refs[key]
# Usage:
store = PlasmaStoreActor.options(name="PlasmaStoreActor", lifetime="detached").remote()
store.put.remote("my_array", np_array)
result = store.get.remote("my_array")
This approach avoids passing ObjectRefs through multiple layers and ensures the actor’s reference keeps the object alive until you explicitly delete it. It also makes debugging and memory management easier, as all references are tracked in one place (see also).
Would you like a step-by-step explanation of how this pattern prevents reference counting errors?
Sources:
- How to cache objects in the object store?
- Getting ReferenceCountingAssertionError when storing ObjectRefs in class variables
- test_reference_counting.py
Hint: Mention @Herald in the post for followups.