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 post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Aram-Azhari · May 15, 2013 at 08:54 AM · editormeshlinerenderer

Heap problem when creating a large number of objects.

Hi.

I ran into this problem yesterday when I was creating a large number of objects in the scene at editor time.

Here's what I do:

  • I have an edit time class and a MenuItem that performs an time consuming operation that involves creating objects in the scene.

  • I have a loop. I read about 200,000 records (one at a time) from a web service and I generate objects for them once at a time.

  • Just about when I reach 18114 number of records processed, the unity hangs, and the memory consumption increases drastically and unity starts to use full cpu power (13% in a quad core hyperthreaded - which means using a thread up to maximum).

  • After a couple of minutes I get the heap error message.

Some notes: - I'm using EditorUtility.DisplayCancelableProgressBar to show the progress. - At each iteration of the loop I create an object either having a linerenderer attached to it or a shape consisting of 20 to 40 triangles (textured).

Things I tried: - Bringing the object and type declarations out of the loop. ex:

 Vector3[] test;
 foreach (var something in aList)
 {
    test=retreiveTheListUsingWebService(something);
    GenerateShapeOrLineRenderer(test);
 }
  • Calling System.GC.Collect after making the possible arrays=null within the loop.

So far, I cannot figure out what the problem is. I have a theory Unity might stack up the GameObject creation commands and waits until the loop ends.

Please if anyone could help me with this I would really appreciate it.

Thank you.

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 whydoidoit · May 15, 2013 at 09:03 AM 1
Share

Hmmm, interesting problem - are you sure that there's not something wrong with the code to generate the object that is being triggered by a particular kind of record? Perhaps you could post the code for GenerateShapeOrLineRenderer?

avatar image Aram-Azhari · May 15, 2013 at 09:05 AM 0
Share

I don't think it's wrong. It works for smaller numbers perfectly and all objects are generated and not even a single error is thrown. It only happens with large number of records. (I've tried 65,000 and it's as smooth as butter)

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Aram-Azhari · May 15, 2013 at 10:33 AM

I finally figured my problem out. As whydoidoit suggested, the internal code was the problem. I traced the problematic record and ran the code within visual studio without involving Unity, I realized it was going into an infinite loop because of some duplicate data.

Comment
Add comment · 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

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

14 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

Related Questions

LineRenderer with nontrivial radius? 1 Answer

Combining meshes into one via editor 2 Answers

Destruction procedural mesh in the editor 0 Answers

What is the best way to fix texture z-fighting? 5 Answers

Editor Script Handles.Label problem. Labels don't move with gameobject 1 Answer


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