On Tue, May 1, 2018 at 1:00 PM,  <time4...@gmail.com> wrote:
>
> I looked at the source but can't understand it well enough.
>
> If I allocate a [1000]byte, or a []byte, I understand the GC will need to
> mark the slice/array itself for collection. However, does the GC mark all
> the bytes within, and does the marking phase attempt to follow all the
> items?

A [1000]byte value holds no pointers, so the GC marks that value once
and does not look inside it.

A []byte holds a single pointer, to the backing array, and the backing
array holds no pointers, so the GC marks the []byte and the backing
array, and then stops.


> Will the GC pause longer if I allocate a large array?

No.

In any case GC pause times are essentially independent of the amount
of allocation you do, since the GC runs concurrently with the program.
Allocating larger values that contain pointers will cause the GC to do
more work, but it won't cause the GC to pause longer.


> Additionally, if the array type is actually [10000]struct{*int}, then surely
> it must follow the array as those pointers may be the only references to
> some data somewhere. Does the GC know not to follow types that contain no
> references?

Yes, and yes.

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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to