Massive memory use

We’re having issues with memory in our app. Besides potential leaks that others have reported elsewhere, it looks like that instead of textures being loaded as needed, all textures in our project are loaded on launch.

We have a very tightly controlled resource system to ensure this doesn’t happen in say, an iOS build, by using ‘weak linked’ textures in scenes, scriptable objects etc to load assets in via addressables when needed.

Since support for addressables isn’t there yet, at build time we convert our project to use Resources/ folders and Resources.Load etc, with all of our scenes being put into the ‘Scenes in build’ list.

On launch however, it seems that there is some mechanism that is finding and loading all textures linked to all scenes, leading to huge amounts of memory being consumed. In fact, we blow straight through th 5GB upper memory limit because our project is pretty big. The only way I have found to work around this is to half-scale all of our assets so they all fit in memory.

To make matters worse, it looks like calling Resources.UnloadUnusedAssets() crashes the app. So we can’t even attempt to clean up.

What’s going on here? Is there a plan to mitigate this?

Thanks,
Joe

This definitely shouldn’t be happening – the lifecycle/memory residency of textures etc. should be the same as that on other platforms. Can you describe in a bit more detail your particular setup so that we can replicate it? Even better would be if you can share a project that reproduces the issue (doesn’t have to reproduce the full 5GB, but just something that uses your specific asset management setup).

Hey there! We’ve identified the issue and we’ll have a fix for it our next release. There’s a call to Resources.LoadAll("") in PolySpatial code that results in everything from Resources getting loaded into memory. It’s part of material conversion so there’s no way to disable or avoid that code path being hit.

I don’t have a precise timeline for when we can deliver the next release, but unfortunately there’s nothing you can do about this on your end aside from reducing the amount of data in Resources. It might be worth trying addressables. The documentation is referring to some specific PolySpatial issues related to loading materials and some other asset types, but addressables as a whole should still work. It may be possible to pick and choose what goes into Resources vs. addressables if you find that some of the addressable assets still work.