FAQ
net/http's Response does not seem to be automatically garbage collected.
https://golang.org/pkg/net/http/
The client must close the response body when finished with it:
Is there any other in Go's packages where we have to be aware of this?

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Ian Lance Taylor at Nov 14, 2015 at 4:38 pm

    On Fri, Nov 13, 2015 at 9:33 PM, Albert Tedja wrote:
    net/http's Response does not seem to be automatically garbage collected.
    https://golang.org/pkg/net/http/
    The client must close the response body when finished with it:
    Is there any other in Go's packages where we have to be aware of this?
    It's not really accurate to say that it is not garbage collected. It
    is garbage collected. It's just that in order to reuse HTTP
    connections the net/http package needs to know when you are done with
    the previous response.

    Any place where you need to be aware of this sort of thing is documented.

    Ian

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Kevin Malachowski at Nov 15, 2015 at 10:51 am
    A good general rule is that if a type has a Close method you probably should call it when you're done with it.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Michael Jones at Nov 15, 2015 at 11:44 am
    …and for that to have been the design, it must be the case that automatically discarding the entity after the initial transaction would have been a general mistake, such as a file being closed automatically after an open, read, or write call. Since a file may well have future reads or writes long after the open, only the higher-level logic that called the open can know when to close. Same with like types and thus the truth is that the data “is not garbage until you say so” outright, via defer, or through some other means.


    Michael Jones, CEO • michael@wearality.com • +1 650 656-6989
    Wearality Corporation • 289 S. San Antonio Road • Los Altos, CA 94022
    On Nov 15, 2015, at 2:51 AM, Kevin Malachowski wrote:

    A good general rule is that if a type has a Close method you probably should call it when you're done with it.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedNov 14, '15 at 4:26p
activeNov 15, '15 at 11:44a
posts4
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase