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 NPS · Sep 25, 2013 at 02:13 PM · iphonememoryloadlevelasync

Application.LoadLevel() doesn't unload current scene?

As in the title - in my game I load a new scene with Application.LoadLevel() and when I profile the app with Xcode Instruments (or what's it called) it shows me under "Real Memory Usage" that it never unloads the previous scene. To be specific: 1st scene takes about 90 MB of memory and 2nd scene is only 1 object and 1 camera so should take much, much less.

(The rest of the post is explaining what I do in detail, if you already know what's wrong you might skip this part.)

Well, to be even more specific I have 3 scenes: Menu, Gameplay and Loading (the one with only 1 object - progress bar). When Menu loads completely "Real Memory Usage" shows about 90 MB. When I want to load Gameplay, the Loading scene is loaded with Application.LoadLevel(). Loading scene does this:

 using UnityEngine;
 using System.Collections;
 
 public class LoadingState : MonoBehaviour
 {
     public static string levelToLoad;
     
     private UISlider slider;
     
     void Start()
     {
         slider = GetComponent<UISlider>();
         var text = GetComponentInChildren<SpriteText>();
         text.Text = MenuState.jsonConfigRoot.GetString("loadingText");
         
         print("LoadingState: Loading...");
         StartCoroutine(LoadLevelWithProgress());
     }
     
     IEnumerator LoadLevelWithProgress()
     {
         var async = Application.LoadLevelAsync(levelToLoad);
         while (!async.isDone)
         {
             slider.Value = async.progress;
             yield return new WaitForEndOfFrame();
         }
     }
 }

So it loads Gameplay with Application.LoadLevelAsync() and display the loading progress.

And it works this way: When Loading starts "Real Memory Usage" shows me around 30 MB which instantly goes up as Gameplay loads. When done it takes about 75 MB. But when I want to come back to Menu (the same way: I load Loading with Application.LoadLevel() which then loads Menu with Application.LoadLevelAsync()), "Real Memory Usage" should drop again but it doesn't, it just keeps taking more memory (over 100 MB) and finally the app is killed by the OS as it apparently doesn't have that much memory (iPhone 3GS).

Any idea why it doesn't unload the Gameplay scene? Any way to force it to do so?

Comment
Add comment · Show 2
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 TonyLi · Sep 26, 2013 at 01:32 PM 0
Share

Are you absolutely sure the Gameplay scene is to blame? Could you have some static classes or managers sticking around that have allocated non-scene memory? $$anonymous$$aybe a pool manager, or loaded assets that somehow have references so they're not unloaded by UnloadUnusedAssets()? Or some objects that are marked DontDestroyOnLoad?

Does System.GC.Collect() have any effect? (It won't garbage collect Unity objects, but maybe the culprit is elsewhere.)

avatar image NPS · Sep 26, 2013 at 05:57 PM 0
Share

I'm not sure so I'll check that and let you know. As for System.GC.Collect() - that was weird. It made my app keep using about 150 $$anonymous$$B whole time (no matter which scene was loaded. Btw I just noticed that today the app used more memory (in each scene) than when I wrote this post... not really sure why. :P

0 Replies

· Add your reply
  • Sort: 

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

17 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

Related Questions

Unity3D app crashes out after error "Warning -> ApplicationDidReceiveMemoryWarning' 2 Answers

Unity ios build and device memory limit 0 Answers

iPhone Game Crashing During Application.Load 0 Answers

Large memory footprint increase when assigning a GUITexture from a WWW Object on iPad 1 Answer

How do I destroy things properly to free up memory? (iOS) 3 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