Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by XeviaN360 · Aug 30, 2011 at 04:01 PM · editorupdateobjectsmemoryleak

Memory Leak Adventures in Editor (3.4, lot of instantiated objects)

Hi Unity Answers. Here's the situation:

  • Unity 3.4 Pro on Windows 7 64 bit

  • an Empty Gameobject with a C# script that runs in the Editor, activated via a public bool flag visibile in the inspector

  • a child object: a plane with a texture on it (2048x2048 uncompressed truecolor)

  • a simple sphere object prefab

The purpose of this script is to create, in the Editor, a prefab that contains numerous objects disposed accordingly to a texture channel.

The script:

Loop inside OnDrawGizmos once flag is activated: .create an empty gameobject (a container for all the instantiated objects) .foreach pixel in texture, if random(1,1000) == 1, instantiate sphere prefab, child of that gameobject .if done, do nothing else

The result is a GameObject with actually a thousand of child spheres. Nice, it works flawlessly.

Now, here comes the strange things: Unity's RAM usage before the generation: 177 MB Unity's RAM usage after the generation: 399 MB Unity's RAM usage after manual deleting all the spheres: 405 MB (!?!)

Hmm. Ok, let's do another cycle: Unity's RAM usage before the generation: 177 MB Unity's RAM usage after the generation: 473 MB (1480 spheres) Unity's RAM usage after manual deleting all the spheres: 475 MB (?!)

Again: Unity's RAM usage before the generation: 475 MB Unity's RAM usage after the generation: 544 MB (1477 spheres) Unity's RAM usage after manual deleting all the spheres: 547 MB (!?)

Someone tells me that Unity or Mono or... do not deallocate memory instantaneously, but only after some "block" memory allocation. Ok, so...

"I can go on." "Do..." (IT Crowd citation)

I'm actually at 950MB of RAM used and it seems not to grow anymore. Maybe this is all caused by the way Windows 7 gives memory to applications. Or is it really allocated? In part? Hmm, i don't know.

BUT, this is not the real problem. The real problem is that if i hit the play button to start the game after a generation is done, memory usage grows at exponential speed (in about 4/5 seconds), goes around 1.1 GB and then Unity crashes with the "Too many heap sections" error (Fatal error in GC). This does not happen if i delete the object that generate spheres (the one with attached script).

Now, i know that using the OnDrawGizmos as a continuos editor Update() could not be really correct. You'll say "ok, there's something in the script that causes memory allocation". The script does nothing when it stops to generate. There is a flag that exits from OnDrawGizmos (tested). The OnDrawGizmos is also enclosed with the #IF UNITY_EDITOR to be sure is not called in game (i think that it's not called however). If i DELETE the object that generate all the spheres, everything goes OK and i can play the game scene.

I can provide a test scene if could be useful.

Thanks in advance.

Comment
Add comment · Show 1
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 BerggreenDK · Sep 18, 2011 at 10:33 PM 0
Share

I am running Unity 3.4 on Win7 64-bit too. I have been wondering why my game becomes very slow in the editor. Tonight I have discovered that the amount of verts and tris, when calculated through scripts gets higher and higher inside the editor from each RUN. $$anonymous$$y guess is that my spawned 500-1000 objects doesnt get deallocated properly when I exit playmode.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by XeviaN360 · Aug 30, 2011 at 04:29 PM

I tryed that script on our main project (with a different object, not the sphere, and with two tousands of objects). When i, from the editor, delete the GameObject that contains all the instanced objects, the memory goes up fast again to 1.4 GB and then the crash. If i delete the "creator object" before, everything goes fine.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Mesh Destroy After an Editor Stop 0 Answers

Unity memory leak when using a drawing tablet? 1 Answer

How to optimize a custom editor ? 3 Answers

Unity Package Manager UI Error Socket IO Unity after updating from 2017.3 to 2018.1.0f2 Nodejs 1 Answer

Coroutine in Editor? 7 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