What is the best way to remove/destroy UTexture2D?

I’m loading in some textures for an interface like so:


int32 currentTextureNumber = iconTextures.Emplace(Cast<UTexture2D>(gameInstance->puzzlesArray[counter].iconTextureRef.Get()));
iconTextures[currentTextureNumber]->AddToRoot();

What is the best way to remove them from memory when no longer needed? I’ve tried the following but do get an error “A FRenderResource was deleted without being released first!”


for (int32 counter = 0; counter < iconTextures.Num(); counter++) {
    iconTextures[counter]->RemoveFromRoot();
    iconTextures[counter]->ReleaseResource();
    delete iconTextures[counter];
}
iconTextures.Empty();

1 Like