Is this correct? about temporary UTexture2D

Hi guys,

In editor plugin module, I create many temporary UTexture2D object, when I save them to disk, did I need to delete them?

is this code correct?

UTexture2D* tmpTex = UTexture2D::CreateTransient(size, size);
// fill tex
DSUtility::FillTex2D(tmpTex, FColor::Black);
FString path = CosmosGenCfg::DefaultAssetPath;
assetName = TEXT("Neblua_");
//	save to new content asset
DSEditorUtility::CreateTexture2DAsset(tmpTex, path, assetName);

// no need this tmpText, how can I destroy it?
// is this correct?
if (tmpTex && tmpTex->IsValidLowLevel())
	tmpTex = nullptr;

anybody can give me some note?

UClass’s such as UTexture2D are automatically garbage collected when there is no hard pointer references made to that object. So if you just leave it and don’t reference it elsewhere then it will be destroyed automatically.

IF you still need to manually remove it I believe you can call ConditionalBeginDestroy() or something like that, but it is probably better to just leave it.

thank you Dec1234