Garbage collection on UObject

i have UObject inherited class

UCLASS()
class PATHFINDING3D_API UCell : public UObject
{
	GENERATED_BODY()

public:
	FIntVector Location;
	UCell* Previous;
	float FCost = 0.f;
	float HCost = 0.f;

	void Initialize(FIntVector _Location, UCell* _Previous, float TotalTravelDistance, float DistanceToEnd);

};

and a struct that allows to put it in TArray

struct FCell {
public:
	UCell* Cell;

	FCell() {}
	FCell(UCell* C) { Cell = C; }
		
	}*/

	FORCEINLINE FCell& operator=(const FCell& Other) {
		Cell = Other.Cell;
		return *this;
	}

	friend bool operator==(const FCell& A, const FCell& B) ;
	friend bool operator<(const FCell& A, const FCell& B);
};

is it required to create a destructor:

~FCell() {
	if (Cell) 
		Cell->ConditionalBeginDestroy();

to be called when i stop using the struct? or will the garbage collector handle it

What? Why are you doing that? You don’t need to do that at all.
TArray<UCell*> Array; works just fine.

I use a HeapPush method when using array, which needsa reference to item. I tried using TArray<UCell*> instead of TArray which just didn’t work.

The comment on heap push:

	 * @note: If your array contains raw pointers, they will be automatically dereferenced during heapification.
	 *        Therefore, your predicate will be passed references rather than pointers.
	 *        The auto-dereferencing behavior does not occur with smart pointers.

So if you have a TArray<UCell*> Array, when you do HeapPush, your predicate would take a const UCell&.

This seems to be working fine for TArray, but I am also using TSet, which seems to no call GetTypeHash:

FORCEINLINE uint32 GetTypeHash(const UCell& Cell)
{
	UE_LOG(LogTemp, Log, TEXT("HASHING CELL"));
	return GetTypeHash(Cell.Location);
}

i see it is possible to working with DefaultKeyFuncs to fix this issue. i will try and comment later on

Well, if you have a TSet<UCell*> then you wouldn’t need a GetTypeHash(const UCell& Cell), you’d need a GetTypeHash(const UCell* Cell).

But for TSets of pointers, you don’t need to manually declare a hashing function because there’s already one that works for pointers. So just delete the function and you’ll be fine.