Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 jamal-dahbur · Aug 13, 2015 at 08:09 PM · unity 5memorymemory management

Why is the memory used of a level going up when entering the level from another level?

So I'm in publishing mode and getting ready to do a final launch of my game and I'm trying to determine what minimum device specification is needed for the game to work perfectly since it's a paid game and I don't want people to download it and not have it work. Well when I start the editor when I'm in a level it will say total memory used 312mb or something around that, and then I exit the editor and go to another level, start the editor and the memory used it 200-300 mb, which is great by me (I'm going to work on making that substantially less in the next update), anyway, when I start testing the full game and I'm in one level the memory used matches what I checked the first time then when I click to go to the next level, the memory spike up, its suddenly 600mb-700mb, and going back and forth it increases a little each time, do I have something wrong? I checked online and one post that's pretty old says that mlnodevelop does not handle garbage collection to well and does clear up used variables once they are no longer in use, is that still true with unity 5? Any tips on how I can make this better?

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
1
Best Answer

Answer by SarperS · Aug 13, 2015 at 10:57 PM

Unity does not clear the previous level until the new level is loaded, and after that it slowly clears it up each garbage collector cycle. A well known trick is to put a very simple loading scene in-between scenes. So you go to the loading screen, it clears up the previous scene while loading the next scene, next scene takes less space because the only garbage is from the much simpler loading scene.

Comment
Add comment · Show 6 · 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 jamal-dahbur · Aug 14, 2015 at 05:49 PM 0
Share

That makes a lot of sense, so I'm currently using loadlevelasync to give a loading screen, do you think I could implement your idea by making a loading scene that has a script that gets a playerpref string and loads the level of that string, and I set the strong when a certain button is pressed?

avatar image SarperS · Aug 14, 2015 at 10:16 PM 0
Share

Sure, below is how I did it and I think it's a better alternative to PlayerPrefs. Let me know if you don't understand how it works.

 using UnityEngine;
 using System.Collections;
 
 internal sealed class Loading$$anonymous$$anager : $$anonymous$$onoBehaviour {
      private static Loading$$anonymous$$anager instance;
 
     internal static Loading$$anonymous$$anager Instance {
         get {
             if(instance != null) return instance;
 
             instance = FindObjectOfType(typeof(Loading$$anonymous$$anager)) as Loading$$anonymous$$anager;
             if(instance != null) return instance;
 
             var container = new GameObject("Loading$$anonymous$$anager");
             instance = container.AddComponent<Loading$$anonymous$$anager>();
             return instance;
         }
     }
 
 
     [SerializeField] private UIProgressBar loadingBar;
     [SerializeField] private ThreadPriority loadingPriority;
 
     private static string sceneToLoad;
 
     internal static string SceneToLoad {
         get { return sceneToLoad; }
         set { sceneToLoad = value; }
     }
 
     private void OnEnable() {
         Application.backgroundLoadingPriority = loadingPriority;
 
         StartCoroutine(LoadAssignedScene());
     }
 
     private IEnumerator LoadAssignedScene() {
         // Wait a single frame so the frame gets rendered
         yield return null;
 
         // Start the loading operation
         var loadingOperation = Application.LoadLevelAsync(SceneToLoad);
 
         while(!loadingOperation.isDone) {
             loadingBar.value = loadingOperation.progress;
             yield return null;
         }
 
         yield return loadingOperation;
     }
 }
 
avatar image jamal-dahbur · Aug 16, 2015 at 05:06 AM 0
Share

Thanks a lot! I'll give both a try and let you know which one I go with

avatar image jamal-dahbur · Aug 25, 2015 at 09:26 AM 0
Share

I've tried it finally but it still doesn't work right, watching the memory profile it seems that it works right when it goes from the game level to the main level, but the main level to the game level the memory still spikes dramatically, the game level started alone used about 450mb, but when loaded from the main menu it spikes up to .75gb (the main menu and the loading scene are around 230mb so it makes sense) however I'm curious to know that even while playing the game scene the memory still doesn't go down, it stays at .75gb. Before I implemented what you said the game level was 1.1 gb so it def helped, however I'm still confused as why it didn't go down to what it is when I start the editor from that level. From what I understood unity should have cleaned it up when the level starts, but well into the level it stays the same...

avatar image SarperS · Aug 25, 2015 at 09:57 AM 0
Share

Did you try profiling the game from the mobile device? Unity Editor might be caching the scenes (a total wild guess here).

Show more comments

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Unity Sprite Memory Usage Is Huge 1 Answer

Do all assets from Assets folder is loading into memory? 1 Answer

Keeping assetbundles in memory vs always loading from cache 1 Answer

why UnloadUnusedAssets doesn't unload a asset? 0 Answers

Scene loading time after upgrade from 5.5 to 5.6 4 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