Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Visartech · Apr 01, 2014 at 02:46 PM · iosassetbundlememorymemory-leakdownloadable content

Unloading asset bundles doesn't clear memory on iOS

Hello.

I'm developing a game with large amount of graphical resources, and I'm using asset bundles to download those resources after the game is installed.

After the start of the game user sees the preloading scene, where asset bundles are downloaded and cached, in order to use them during the game.

The following code is used for caching asset bundles:

 using UnityEngine;
 using System;
 using System.Collections;
 using System.Collections.Generic;
 
 public class AssetBundleLoader : MonoBehaviour {
 
     const string BaseURL = "http://192.168.1.46/AssetBundles/";
     static List<string> assetBundleNames = new List<string>
     {
         // Asset bundle names
     };
 
     // Use this for initialization
     IEnumerator Start () {
         foreach (string assetBundleName in assetBundleNames) 
         {
             string fullAssetBundlePath = BaseURL + assetBundleName;
             using (
                 WWW download = WWW.LoadFromCacheOrDownload(fullAssetBundlePath, 1))
             {
                 yield return download;
 
                 if (!string.IsNullOrEmpty(download.error))
                     continue;
 
                 AssetBundle bundle = download.assetBundle;
                 bundle.Unload(true);
             }
         }
 
         yield return Resources.UnloadUnusedAssets ();
         GC.Collect ();
     }
 }


The problem is that bundle.Unload(true) doesn't clear the memory. Thus, when I try to cache a lot of asset bundles in my scene, the game crashes due to Memory Pressure on iPad 2.

Any ideas on how to handle this would be useful. Thank you.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by StormTeam · Aug 12, 2014 at 06:57 PM

I believe it is actually the WWW that is leaking, not the asset bundle itself. Thus, unloading the asset bundle won't help. We ran into a similar issue in our app. We were loading lots of textures from WWW and noticing iOS being the only platform to have a memory leak from it. We eventually found our solution here http://forum.unity3d.com/threads/www-memory-leak-ios.227753/. Basically, there is a known issue in unity 4.3 that leaks the data from www calls. This SHOULD be fixed in unity 4.5. In the meantime, you can follow Alexey's suggestion to modify the code in the generate xcode project or update to 4.5:

will have the fix.

Essentially you need: search for extern "C" void UnityDestroyWWWConnection(void* connection) in WWWConnection.mm [delegate.connection cancel]; delegate.connection = nil; [delegate.data release]; // <-- ADD THIS [delegate release];
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image pushxtonotdie · Oct 23, 2014 at 07:24 PM 0
Share

Just figured I'd confirm. This is fixed in Unity 4.5. I am running 4.5.1 and the UnityWWWConnectionDelegate class has a 'cleanup' method which now releases the _data inside.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Does assetbundle work well with mobile devices? 1 Answer

Memory Allocation Continues to Grow? iOS. 4.6.3 0 Answers

Memory leak using bundles. 1 Answer

AssetBundle.Unload(False) in IOS Save Reference ? 0 Answers

mp3 files giving ios memory warning 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges