Closing client's connection
There isn't any Close() function provided for closing a connection from client side. Probably there is a way to close the connection by manipulating the freeconn attribute of the client instance, but I am not sure if this is a safe solution. Can anyone provide a safe solution for closing a connection from client side?
and also need some method to destroy whole client..
@lysu, I believe that you can destroy the whole client just by nullifying the instance. E.g.:
// Create the memcached client mc := memcache.New("10.0.0.1:11211", "10.0.0.2:11211", "10.0.0.3:11212") // Destroy it mc = nil
The GOlang's garbage collector will do all the necessary work for you.
@anaktas yes...GC will recycle memory and some resource but it's better to close resource by ourself...
for this one, pooled network fd will be added to runtime.SetFinalizer, and close them when gc occur, but the time to close is not predict, it's maybe too late for some situation..
except that... do slow things like "close fd" in finalizer will slower GC..
@lysu you have right, I agree with you. You can still use the runtime.GC() to force the GC to run at your demand, but this would have some impact (probably a significant) in the performance of your application.
Yes, I had the same question. I wonder if @bradfitz has a good solution to do this cleanly.
Any update?
I opened this PR, https://github.com/bradfitz/gomemcache/pull/155