Assetbundle and memory management

Hi,

I created a webGL app that would load 87 asset bundles. Each asset bundle is approximately the same size, and all they contain are game object hierarchy of meshes.

At the start of the app it will load in all 87 bundles - which deems to be too much for WebGL build, thus it runs out of dynamic memory:

Looking at the memory consumption, the current dynamic memory used is always very low, but every time a bundle is loaded total Dynamic memory always increases. At the point of crashes, I’m not using that much dynamic memory (note: Dynamic memory used is taken from System.GC.GetTotalMemory(false)):

Base on my memory tracker, there is plenty of free memory that is not being used, yet everytime I load an asset bundle it seems to always need to allocate more memory (despite every bundle are similar in size).

The bundles are loaded via generating a WWW object and yielding it, so I believe I’m not trying to cache the object. It seems like something is consuming my dynamic memory that isn’t displayed from System.GC.GetTotalMemory? Could it be memory fragmentation?

After reading a lot of info about WebGL memory I’m still at a lost as to why this happens. Just wondering if I can get any insights as to what happens when I load a bundle (or multiple in this case!, and Is there anything I can do about my current situation.

Many thanks!

so you are using 2gb of memory? seems quite a lot for web content.

Hare you read these blog posts? I think the second one is probably more relevant for you since you are running out of memory in the Unity Heap

Hi Marco,

I am trying to load an engineering model on the web, thus it is not a typical game scenario! :slight_smile: The reason for using 2GB memory is also because of the situation explained on my post.

I have read both blog posts before. The second post is where I got the code to examine the memory. None of them seems to explain this behaviour of expanding dynamic heap when I’m only using a fraction of the amount. Nor do they tell me what affects does loading an asset bundle has to my dynamic memory. I am not using WWW.LoadFromCacheOrDownload to fetch my bundles so according to the first post it would have only done some temporary allocations.

Any light on this matter will be highly appreciated!

If your problem is managed memory consumption I would recommend you to profile it to see exactly what’s in memory. If your project is large, it might be tricky to do on Unity WebGL, so maybe try a different platform. Perhaps you have some managed objects that are never deallocated? System.GC.Collect() should work as of 5.6, though with a frame delay.