The memory of cesium for ue4

I have put 3dtiles data in the scene ,and I can see the data in the Cesium viewer.
It is easy to notice that the memory increases when a new tile loading,but never decrease.
It seems the tile data not be released property.
Is it a bug? Can any tell me more about it?

Hi @duanmang,

We recently discover a memory leak when decoding textures. The bug is fixed in this PR and will go out to the next release.

Beside the bug, currently, we recently find out that unreal’s garbage collection won’t kick in during the editor mode. To force it, you can use gc.CollectEveryFrame 1 in the editor command console

Bao

Thanks for your answer!

I found the code is different from your version.May be my code is newer.It seems the problem has been resolved.(Code1)

I found another place may lead the memory leak.We use the class HalfConstructedReal to produce the StaticMeshComponent. There is std::vector loadModelResult in HalfConstructedReal. There might be some LoadModelResult instances not released, because they never had a chance to be passed to their staticMeshComponent in time. Where do you think we should deal with them. All the best.

Code1:

GltfReader::readImage(const gsl::span& data) const {
ImageReaderResult result;

result.image.emplace();
ImageCesium& image = result.image.value();

image.bytesPerChannel = 1;
image.channels = 4;

int channelsInFile;
stbi_uc* pImage = stbi_load_from_memory(
reinterpret_cast<const stbi_uc*>(data.data()),
static_cast(data.size()),
&image.width,
&image.height,
&channelsInFile,
image.channels);
if (pImage) {
const int lastByte =
image.width * image.height * image.channels * image.bytesPerChannel;
// std::uint8_t is not implicitly convertible to std::byte, so we must use
// std::transform here to force the conversion.
std::transform(
pImage,
pImage + lastByte,
std::back_inserter(image.pixelData),
(char c) { return std::byte(c); });
stbi_image_free(pImage);
} else {
result.image.reset();
result.errors.emplace_back(stbi_failure_reason());
}

return result;
}