Hello,
I have a class
.H File
`#pragma once
#include "GameFramework/Actor.h"
#include "Test.generated.h"
class ss
{
public:
ss()
{
}
~ss()
{
UE_LOG(LogTemp, Log, TEXT("Deleted ss"));
}
};
UCLASS()
class R_API ATest : public AActor
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "FSFollowcam")
bool CanDelete = false;
ss* s1 = nullptr;
ss s2;
// Sets default values for this actor's properties
ATest();
~ATest();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
};`
.Cpp File
// Fill out your copyright notice in the Description page of Project Settings.
#include "R.h"
#include "Test.h"
// Sets default values
ATest::ATest()
{
s1 = new ss();
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void ATest::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ATest::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
UE_LOG(LogTemp, Log, TEXT("Update Called"));
}
ATest::~ATest()
{
if (CanDelete)
{
delete s1;
s1 = nullptr;
}
UE_LOG(LogTemp, Log, TEXT("Test Actor Deleted"));
}
Now what i did is i created a blueprint that is inherited from this class and inside that blueprint i am checking if “E Key” is pressed.If “E Key” is Pressed i am destroying the actor.Now the problem is when i drag and drop this actor into the empty scene and when i click play i get the log for the Tick() method that’s inside ATest class.But as soon as i press the “E Key” while i am in Play Mode Actor is destroyed but i don’t get any logs that’s inside ~ATest class Destructor.But logs for the ~ATest class destructor are printed when i press the stop button.I tested it in windows 7.Does this mean memory won’t be released until we exit out of Play Mode?
Thanks,