- Home /
Memory overhead associated with assets in Resources
We have our game set up to load different assets (usually textures) depending on the iOS device we're running on. These assets are specified by path in the object that uses them, then one is chosen at run time and loaded via Resources.Load( ... ).
That seems to work fine.
As we've added new assets to the Resources directory, however, the baseline memory use of our game is increasing. It seems that just having additional assets inside Resources is causing more memory to be used, even when those assets are not loaded. Purging assets with Resources.UnloadUnusedAssets( ... ) does not recover that memory.
All my memory measurements are done inside Apple's memory monitor instrument.
Does anyone know what could be going on here? Is this the proper/best/only way to dynamically choose which assets to load?
Update
The extra memory is tracked by the Allocations instrument, which reports an additional ~5M and ~46,000 allocations when these assets are in the Resources folder. That would apparently rule out textures or other render data that isn't reported by that instrument.
You may have references that is causing additional assets to load than intended. Do you prefabs linking to other prefabs? I had a similar issue once before and removing the references fixed it.
I'm seeing the increase in memory use before loading any of the new assets or prefabs that reference them. Just having them in the resources directory seems to incur some memory overhead.
II'll definitely be doing further testing and I'll post anything else I find.
Apparently Unity creates a large lookup graph for everything stored in Resources (in a file called 'mainData'). That graph is always loaded and can potentially take up a lot of memory--substantially more than the file size alone would suggest.
Your answer
Follow this Question
Related Questions
Prevent Resources class from loading assets when application starts 1 Answer
ResourceManager Class Referencing Assets? 1 Answer
Best way to manage hundreds of materials? 1 Answer
Memory problem. How do I dump a Streaming Asset from memory? 1 Answer
Loading a Random Resource in a Folder Without Using Resources.LoadAll 0 Answers