Skip to content

Conversation

@skshetry
Copy link
Collaborator

@skshetry skshetry commented Oct 28, 2025

Using a bound method with weakref.finalize was keeping a reference to the SSHFileSystem instance, preventing it from being garbage collected.

sshfs/sshfs/spec.py

Lines 73 to 75 in e371f39

weakref.finalize(
self, sync, self.loop, self._finalize, self._pool, self._stack
)

async def _finalize(self, pool, stack):

See note at the end of the Python documentation for weakref.finalize:

Note: It is important to ensure that func, args and kwargs do not own any references to obj,
either directly or indirectly, since otherwise obj will never be garbage collected.
In particular, func should not be a bound method of obj.

Using a bound method with weakref.finalize was keeping a reference
to the `SSHFileSystem` instance, preventing it from being garbage
collected.

See note at the end of the Python documentation for [`weakref.finalize`][1]:

> Note: It is important to ensure that func, args and kwargs do not own any references to obj,
> either directly or indirectly, since otherwise obj will never be garbage collected.
> In particular, func should not be a bound method of obj.

[1]: https://docs.python.org/3/library/weakref.html#weakref.finalize
@skshetry skshetry requested a review from shcheklein October 28, 2025 15:55
Copy link
Collaborator

@shcheklein shcheklein left a comment

Choose a reason for hiding this comment

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

thanks!

@skshetry skshetry merged commit 99389dd into fsspec:main Oct 28, 2025
20 of 21 checks passed
@skshetry skshetry deleted the weakref-finalize-static branch October 28, 2025 16:41
@skshetry skshetry moved this to Review In Progress in DVC Nov 3, 2025
@skshetry skshetry added this to DVC Nov 3, 2025
@skshetry skshetry moved this from Review In Progress to Done in DVC Nov 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants