UE 4.7.3 / PC Windows
Hi, I have a little problem with managing the TArray of UTextures2D.
I’m making textures from data received from HTTP request and store it into the Array:
TArray< uint8 > JPGData;
JPGData.Append(HttpResponse->GetContent());
IImageWrapperPtr JPGWrapper = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper")).CreateImageWrapper(EImageFormat::JPEG);
JPGWrapper->SetCompressed(JPGData.GetData(), JPGData.Num());
const TArray<uint8>* UncompressedRGBA = NULL;
JPGWrapper->GetRaw(ERGBFormat::BGRA, 8, UncompressedRGBA);
UTexture2D* NewAvatar = UTexture2D::CreateTransient(JPGWrapper->GetWidth(), JPGWrapper->GetHeight(), PF_B8G8R8A8);
NewAvatar->MipGenSettings = TMGS_NoMipmaps;
void* TextureData = NewAvatar->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
FMemory::Memcpy(TextureData, UncompressedRGBA->GetData(), UncompressedRGBA->Num());
NewAvatar->PlatformData->Mips[0].BulkData.Unlock();
NewAvatar->UpdateResource();
CustomAvatars.Add(NewAvatar);
The CustomAvatars is a TArray:
UPROPERTY(BlueprintReadOnly, Category = "ServerTests")
TArray<UTexture2D*> CustomAvatars;
I was using Stat MEMORY and Stat MEMORYPLATFORM to track “Used Virtual” and “Texture Memory Used”. After few downloads the memory changed:
“Used Virtual”: 435MB → 504MB
“Texture Memory Used”: 21MB → 55MB
Then I used a method for clearing that data:
if (CustomAvatars.Num() > 0)
{
for (auto Itr(CustomAvatars.CreateIterator()); Itr; ++Itr)
{
if ((*Itr)->IsValidLowLevel() == true)
{
(*Itr)->ConditionalBeginDestroy();
*Itr = nullptr;
}
}
CustomAvatars.Empty();
}
GameInstance->GetWorld()->ForceGarbageCollection(true);
The “Texture Memory Used” went back to the 21MB, but “Used Virtual” is still the same.
Mine question is: Is it normal? Won’t it cause a crash by no memory? Do I do something wrong when creating/removing objects in the array?