Will aggressive GC occur when UPROPERTY fields converted to local variable?

In my current understanding, UPROPERTY() is mandatory for fields of type pointer to UObject derived classes. Garbage Collector iterate its fields and only does graceful destruction on fields with UPROPERTY().

What happens when I remove the field Mesh in version 1 and place it as a local variable in version 2?
Does the danger of being aggressively destructed by GC exist in version 2 (because it no longer has UPROPERTY())?

// Version 1: Using fields

class MYPROJECT_API AMyActor : public AActor

{

    GENERATED_BODY()

    UPROPERTY()

        UStaticMeshComponent* Mesh;

}

AMyActor::AMyActor()

{

    Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));

    RootComponent = Mesh;

    // Other components are initialized below this line.

    // OtherComponent->SetupAttachment(Mesh);

}
// Version 2: Without using fields

class MYPROJECT_API AMyActor : public AActor

{

    GENERATED_BODY()

}

AMyActor::AMyActor()

{

    UStaticMeshComponent* Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));

    RootComponent = Mesh;

    // Other components are initialized below this line.

    // OtherComponent->SetupAttachment(Mesh);

}

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms