How to release UTexture2D objects correctly?

    FString path = FPaths::ProjectDir() + "Content/VideoAnalysis/colorbar.png";
	UTexture2D* pColorMap = ImportImage(path, EImgFormat::PNG);
	if (pColorMap)
	{
		FTexture2DMipMap& mipmapColorMap = pColorMap->PlatformData->Mips[0];
		unsigned char* DataColorMap = (unsigned char*)mipmapColorMap.BulkData.Lock(LOCK_READ_WRITE);
		mipmapColorMap.BulkData.Unlock();
	}

Hi Mlrro1871,

You don’t need to do anything - once the pColorMap goes out of scope garbage collection will clean it up. You can call BeginDestroy() once you’ve finished with it to get it ready to be deleted.

1 Like