CesiumGS / cesium-native

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Memory leak when using external tilesets.

ZackOfAllTrades opened this issue · comments

While working with the Google dataset I've been running out of memory. Looking at the call stack
image
It is clear it has to do with external tilesets and indeed if the content is external it is not unloaded as part of the _unloadCachedTiles update.
image

In practice even when I set maximumCachedBytes to 0 the _loadedTiles will continue to grow indefinitely
image

I don't have enough context on how external tilesets are used so I could be way off but it seems like there needs to be some kind of tree-trimming functionality to unload parts of the explicit json tile tree that are no longer in use.

Can you provide a particular location you were viewing? Also, how long of a session were you in before it crashed?

Ex. Flying the camera around Manhattan for 10 mins straight.

Just trying to establish an easy scenario, so it can be reproduced quickly.

Hi thanks for the response, the location does not matter and on my pc I too can almost endlessly zoom around but the memory does increase. I've only crashed on hololens2 where I have very little working memory.

I'm sure it has to do with never evicting the explicit external tileset json files, these can be quite large.
image
image

Ok great, thanks for the clarification.

On Windows 10, I was also able to reproduce what appears to be a memory leak, but no crash. I watched the Task Manager memory usage for UnrealEditor.exe and could see it grow ~4GB in my tests. It went up and down during this time, but it definitely didn't stay within the Maximum Cached Bytes setting of 268,435,456

This was in cesium-unreal-samples, 12_CesiumGoogleMapsTiles.umap, flying from the Googleplex to NYC and around the dense buildings in Manhattan.

Indeed the external tileset data isn't unloaded. Generally that's not a major problem, but in the case of Google Photorealistic 3D Tiles it adds up pretty quickly. A couple of minutes flying around can easily end up with a gigabyte of Tile instances in memory.

It's not easy to unload this data, because we need to make sure it's not being used when it's unloaded. For example, one of the Tile instances in the external tileset could be in the process of being loaded in a worker thread at the moment we decide the root Tile of the external tileset can be unloaded. If we actually went through with the unloading, we'd end up deleting a Tile in one thread while it's in use in another.

But this is certainly solvable, and it's worth solving.

But this is certainly solvable, and it's worth solving.

if it's worth solving, which i already am fully aware of, please make this bugfix top-priority in your to-do list.

Worth solving is not the same as top priority, I'm afraid, but we do plan to do this as soon as we can. If you need it sooner, remember that cesium-native is open source and we welcome pull requests.

👍 appreciate it, just pointing out how important it is, nothing else.