ClientProxy and connection have a circular reference, causing Python not to be able to garbage collect. #25
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Found a circular reference that may have been causing memory leak issues. The offending code appears to be the _ClientProxy() class that takes in a connection object. Since the connection.client points to _ClientProxy() and _ClientProxy() instance is pointing back to connection, Python fails to call the del function inside the Connection class.
See the problem? ClientProxy points to connection, and connection.client points to ClientProxy.
I put inside the del(self) of connection to verify the connection will die:
With this fix, the print "dying" appears and memory is reclaimed after the ConnectionPool() instead goes out of scope (http://eli.thegreenplace.net/2009/06/12/safely-using-destructors-in-python/).
Is there a way to avoid this issue by avoiding needing to pass the connection object into the ClientProxy?