Closes the connection when the object is destroyed