Skip to content

Fix Ray Tune memory leak by clearing dangling ObjectRef#64236

Open
gmrnlg1971 wants to merge 1 commit into
ray-project:masterfrom
gmrnlg1971:fix/ray-tune-memory-leak-64231
Open

Fix Ray Tune memory leak by clearing dangling ObjectRef#64236
gmrnlg1971 wants to merge 1 commit into
ray-project:masterfrom
gmrnlg1971:fix/ray-tune-memory-leak-64231

Conversation

@gmrnlg1971

Copy link
Copy Markdown

Thank you for contributing to Ray! 🚀
Please review the Ray Contribution Guide before opening a pull request.

⚠️ Remove these instructions before submitting your PR.

💡 Tip: Mark as draft if you want early feedback, or ready for review when it's complete.

Description

Briefly describe what this PR accomplishes and why it's needed.

Related issues

Link related issues: "Fixes #1234", "Closes #1234", or "Related to #1234".

Additional information

Optional: Add implementation details, API changes, usage examples, screenshots, etc.

@gmrnlg1971 gmrnlg1971 requested a review from a team as a code owner June 20, 2026 18:44

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the set_ray_actor method in trial.py to set self._default_result_or_future to None when ray_actor is not provided. The reviewer suggests conditionally clearing this attribute only if it is a ray.ObjectRef to prevent discarding useful metadata when it has already been resolved to a dictionary.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +685 to +686
else:
self._default_result_or_future = None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If self._default_result_or_future has already been resolved to a dict (e.g., via last_result or _get_default_result_or_future), it is a plain Python dictionary and does not hold any Ray object references, so it cannot cause a Ray memory leak. Clearing it unconditionally discards useful metadata (like node_ip and pid of the trial) which might be needed for debugging or post-mortem analysis of the trial.

Consider only clearing self._default_result_or_future if it is indeed an instance of ray.ObjectRef.

Suggested change
else:
self._default_result_or_future = None
else:
if isinstance(self._default_result_or_future, ray.ObjectRef):
self._default_result_or_future = None

@ray-gardener ray-gardener Bot added tune Tune-related issues community-contribution Contributed by the community labels Jun 20, 2026
Signed-off-by: gmrnlg1971 <gmrnlg1971@users.noreply.github.com>
@gmrnlg1971 gmrnlg1971 force-pushed the fix/ray-tune-memory-leak-64231 branch from a20bb71 to eca35b0 Compare June 21, 2026 01:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community tune Tune-related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ray fails to serialize self-reference objects

1 participant