Assetbundle memory leak (Unity 5.3.1)

Hello,
I have encountered a memory leak on assetbundle load. After download a bundle using WWW, I save it on disk and then loading, using this code:

AssetBundleCreateRequest assetBundleCreateRequest = AssetBundle.LoadFromFileAsync(path);
yield return assetBundleCreateRequest;
assetBundle = assetBundleCreateRequest.assetBundle;

And then just unloading bundle

assetBundle.Unload(true);
assetBundle = null;
Resources.UnloadUnusedAssets ();

After memory from bundle is released we have extra 0.5mb added. This happen every time I load and unload assebundle, so memory grows until app crashes. This assetbundle was created with ChunkBasedCompression option. And no matter what bundle size,it always add about 0.5mb after unload. I have tested it with 100 kb, and 5 mb aseetbundle.
I have tested it on windows phone and ios device, so it’s not platform specific. Have anybody else can confirm this bug. Should I submit a bug report? It’s easy reproducable. Here is a profiler screenshots
Before :

After:

Nice find, I think a bug report to Unity will help get this solved if issue is present.
Yes they love it when you file bugs :slight_smile:

Bug reported yesterday but no any confirmation yet. Case number 756909

1 Like

Hi. Fellow
I also have same problem.
I wonder What`s going on case number 756909?
Is it already confirmed or not.

Bug 756909 was closed with “this issue is OS X only and is fixed in Unity 5.4.0b1”

Thank you a lot!!!

We had encountered the same problems that you have. Our project loads Asset Bundles from server and save them on the disk and later load them to the game. We found this problem on Android. After long trial and error, we are finally able to solve this issue with Unity 5.3.2

To solve this. Just make sure that you build the asset bundle with either option BuildAssetBundleOptions.ChunkBasedCompression (introduced in 5.3) or BuildAssetBundleOptions.UncompressedAssetBundle. Then use AssetBundle.LoadFromFile(or Async) to load the asset bundle.

Here are some funny things we found out.

  1. If asset bundles are built without either BuildAssetBundleOptions.ChunkBasedCompression or BuildAssetBundleOptions.UncompressedAssetBundle. There is still memory leak.

  2. If uncompressed asset bundle have been loaded even once with LoadFromFile, compressed asset bundle (without BuildAssetBundleOptions.ChunkBasedCompression) can be loaded with no memory leak.

  3. LoadFromMemory seems to always leak except if asset bundle built with BuildAssetBundleOptions.ChunkBasedCompression or BuildAssetBundleOptions.UncompressedAssetBundle are loaded with LoadFromFile first then later loading with LoadFromMemory is no longer causing memory leak.

Hope this information helps.

1 Like