How SetupAttachment works?

from https://docs.unrealengine.com/en-US/Programming/Tutorials/Components/index.html, this code is in the constructor:

USpringArmComponent* SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraAttachmentArm"));
SpringArm->SetupAttachment(RootComponent);

How can unreal keep track of SpringArm? because SpringArm is declare here, it is not a class member.
Is it somehow make a copy of SpringArm and set it up with RootComponent?

As you guessed, the SpringArm is being attached to the RootComponent.
Since the you are inheriting from AActor, your child actor class already has a RootComponent and it does not need to be specified in its members.