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 Retribution · Nov 17, 2011 at 11:03 PM · iphonememorymemory-leak

Assets never unloading after loading next scene

I'm having an issue in an iOS app where my assets for each different scene are not being unloaded once I load another scene. Here's some background on what I'm doing:

I was having memory issues when loading a scene with Application.LoadLevel(), so I changed to loading a blank scene between each level and using Application.LoadLevelAdditively() as discussed in this topic. This helped and I'm able to actually load the scenes now on an iPad1, however I noticed after loading a few scenes I was receiving the low memory warning again. Come to find out my loaded object count was never dropping based on this printout from XCode:

 Unloading 18 unused Assets to reduce memory usage. Loaded Objects now: 221.

This amount steadily increases as I change scenes, and rarely removes any unused assets. These scenes share very few common assets, so nearly all of them should be being restored after I change scenes, or at least I assumed they should.

I'm using SpriteManager1 in this project to manage/draw sprites and I've heard of a few others stating they had issues releasing assets from SpriteManager. However, I have several other assets (Camera objects, GameObjects with just scripts attached, etc) that are persisting through these scenes as well, so mine issue seems to be related to every Object in my scenes.

I'm also monitoring how much memory I'm using through a simple prinout in objective-c by using:

 - (void) report_memory:(NSTimer *)timer {
 struct task_basic_info info;
 mach_msg_type_number_t size = sizeof(info);
 kern_return_t kerr = task_info(mach_task_self(),
                                TASK_BASIC_INFO,
                                (task_info_t)&info,
                                &size);
 if( kerr == KERN_SUCCESS ) {
     //NSLog(@"Memory in use (in bytes): %u", info.resident_size);
     printf_console("Memory in use (in bytes): %u\n", info.resident_size);
 } else {
     //NSLog(@"Error with task_info(): %s", mach_error_string(kerr));
     printf_console("Error with task_info(): %s\n", mach_error_string(kerr));
 }

}

I print this information every 2 seconds just to quickly gauge how much memory my scenes are requiring. Of course, this increases in size as my assets continue to pile up and never unload as I change scenes.

I've tried manually calling the garbage collector as I load levels and I call Resources.UnloadUnusedAssets() during my blank scene just to be sure we're trying to clear the unused assets, but these proved unsuccessful.

I'm using the Unity Pro version 3.4.2 with the iOS Pro license if that makes any difference.

Thanks

Comment
Add comment · Show 3
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 kayy · Nov 18, 2011 at 12:46 PM 0
Share

Sounds like there are other objects that are holding references to those that are supposed to be unloaded. $$anonymous$$aybe you have a level engine or similar stuff that keeps them within an array?

avatar image barskya · Mar 08, 2012 at 08:34 AM 0
Share

Hey, did you solve this problem?

Thanks.

avatar image saud_ahmed020 · Mar 25, 2015 at 01:46 PM 0
Share

Hi, Retribution had your problem been solved??

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Rod-Green · Nov 18, 2011 at 07:19 PM

Do you have any "#if"s i.e "#if UNITY_ENGINE" around any serialized properties? I found this causes unpredictable asset retention.

You could also do a find query in the blank level to see what behaviors are remaining.

FindSceneObjectsOfType(typeof(Behavior));

Then see which of these might be retaining connections.

Comment
Add comment · Show 2 · 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 Retribution · Nov 21, 2011 at 06:43 PM 0
Share

I did have quite a few #if PLATFOR$$anonymous$$ checks in my code, I commented those out to see if it would make a difference but unfortunately it did not.

I've printed what assets still exist between level loads ($$anonymous$$eshes, $$anonymous$$aterials, scripts, etc) and it just doesn't seem to be deleting any of them. I am still looking through these for now though to see if any of these objects, for whatever reason, would be holding their references between loading these scenes.

avatar image Rod-Green · Nov 21, 2011 at 08:21 PM 2
Share

What about hideflags? Are they set to 'don't save'? Anything set to 'dontdestroyonload' ?

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

7 People are following this question.

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

Related Questions

webgl memory leak 1 Answer

Shader import error: Out of memory, but not really 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

Unity not unloading procedurally generated mesh when parent GameObject is destroyed and its not referenced 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