SshConnection registers an atexit handler so the connection is closed upon exiting the process if it has not been done before. However, the handler keeps a reference on the connection, which means it will stay alive. If lots of short-lived connections are created (which can happen when using e.g. ThreadPoolExecutor), they will simply stay around and leak.
Fix that by using a weak reference (WeakMethod) to register in the atexit handler, with a callback to unregister it when the object is deallocated.
SshConnection registers an atexit handler so the connection is closed upon exiting the process if it has not been done before. However, the handler keeps a reference on the connection, which means it will stay alive. If lots of short-lived connections are created (which can happen when using e.g. ThreadPoolExecutor), they will simply stay around and leak.
Fix that by using a weak reference (WeakMethod) to register in the atexit handler, with a callback to unregister it when the object is deallocated.
Fixes https://github.com/ARM-software/devlib/issues/676