On Mon, Nov 11, 2024 at 9:02 AM Bosung Park <
bosun...@tryalign.ai> wrote:
>
> I understand that unreferenced channels will eventually be garbage collected, along with any objects in their buffer.
> So, it is not actually memory leak.
>
> However, I am curious if there is a possibility that, until the garbage collection occurs,
> the accumulation of unnecessary memory could appear as a memory leak during monitoring?
>
> Or, garbage collection occurs occurs immediately, that there is no possibility that the accumulation of unnecessary memory could appear during monitoring?
An unreferenced channel will not be collected immediately. This is no
different from an unreferenced slice, or any other type. This delay
is something to consider when monitoring memory usage. That is true
for all types, and there is nothing special about channels in this
regard.
Ian
> On Friday, March 1, 2024 at 11:34:55 PM UTC+9 Ian Lance Taylor wrote:
>>
>> On Fri, Mar 1, 2024 at 6:26 AM Shubha Acharya
>> <
shubhaac...@gmail.com> wrote:
>> >
>> > I have been working with buffered channels. I have stumbled upon a scenario where buffered channel will be closed and the receivers of the channel terminates before consuming all the elements in the buffer. So my question is will there be any issue regarding Garbage Collection of channel which eventually leads to memory or resource leaks because of the left out items in the buffer? or any other concerns that I must be aware of?
>>
>> No more than, say, a slice. An unreferenced channel will be garbage
>> collected, which will remove references to any objects in the channel
>> buffer. If those objects have no other references, they too will be
>> garbage collected.
>>
>> 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...@googlegroups.com.
> To view this discussion visit
https://groups.google.com/d/msgid/golang-nuts/090fc9eb-36b6-4522-8e49-4e4a5ce4b101n%40googlegroups.com.