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 /
This question was closed Jan 26, 2014 at 09:07 AM by Nick4 for the following reason:

Too subjective and argumentative

avatar image
0
Question by Nick4 · Jan 25, 2014 at 02:34 PM · crashloopsfatal error

Too many nested loops cause fatal error(?)

I have 2 nested loops, each has 9 or 10 foreach loops and if statements nested. When I try to play in editor, I get an error message that says "Fatal error! Could not allocate memory : System out of memory". I'm developing for mobile. What I have in my scene is just a few spheres and blocks. Nothing fancy to crash Unity. I think it's that nested loops that cause the problem. Do you know what may cause fatal error or did you have trouble using bunch of nested loops in Unity before?

Comment
Add comment · Show 5
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 Jamora · Jan 25, 2014 at 03:00 PM 1
Share

Nesting loops won't cause a system out of memory error; it's what you do in those loops.

 for(int i=0;i<10;i++){
     for(int j=0; j<10; j++){
         for(int k=0; k<10; k++){
             //This block is run 1 000 times.
         }
     }
 }

Now, if this is in your Update, you will have run the innermost block ~60 000 times (assu$$anonymous$$g 60 FPS) in a second. Even allocating a new string in that loop could cause a system out of memory error.

avatar image Nick4 · Jan 25, 2014 at 03:22 PM 0
Share

I don't use them in my update function. I get one time ride then delete unnecessary variable values.

avatar image oatsbarley · Jan 25, 2014 at 05:48 PM 2
Share

What are you doing in the loop? It's hard to solve your problem without knowing what might be allocating memory.

avatar image Owen-Reynolds · Jan 25, 2014 at 06:29 PM 2
Share

To echo Jamora, you're probably miscounting the # of times the loops run, and really are allocating too much (9 or 10? So, you have more loops than you can count?)

Or, another commonish problem, a foreach is going through a list and growing that list at the same time, so runs forever.

avatar image Nick4 · Jan 26, 2014 at 09:06 AM 0
Share

No, nothing like that and it's not that big deal. $$anonymous$$y list elements aren't more than 10. I guess it's an unnecessary way to use that much memory. I'll find a better way. Thank you all.

0 Replies

  • Sort: 

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

gc: too many threads, crash using Unity 4.2 8 Answers

Fatal Error While Playing -- VertexData.cpp 0 Answers

crash on android devices (unity 4.6f1) 2 Answers

Unity crashes when opening a project. 1 Answer

FATAL EXCEPTION [UnityMain] 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