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 oakus · Mar 12, 2014 at 04:19 PM · arraysserializationrecursion

Serializing class that has List of members of same type and referencing them in scene causes awfull long assembly reload time

Scenario:

  1. Have a class that is [Serializable] and contains couple private members - Lists of same class like this

[Serializable]

 public class SerializationListRecursionTest
 {
     private List<SerializationListRecursionTest> list1;
     private List<SerializationListRecursionTest> list2;
     private List<SerializationListRecursionTest> list3;
     private List<SerializationListRecursionTest> list4;
 }

  1. Have a MonoBehaviour class that references that class couple times, like this

    public class TestStateReference : MonoBehaviour { private SerializationListRecursionTest serializationListRecursionTest;

      private SerializationListRecursionTest serializationListRecursionTest1;
     
         private SerializationListRecursionTest serializationListRecursionTest2;
     }
    
    
  2. Have an empty scene and add like six objects that each has this MB attached

  3. Do a code change (or force assembly reload in any way)

  4. Unity editor freezes for couple seconds, memory consumption goes high (from around 110MB in this empty project to like 800MB and then goes low again). Assembly reload finishes. You might say its not that bad. But once there are more objects that references this one class or this clas is referenced indirectly from some other object, the consumption goes up to around 2.3GB and it takes around 20s or longer to reload the assembly.

Notes

  • removing serializable attribute makes problem go away

  • replacing List with just type makes problem go away

  • using simple arrays instead of list does not make problem go away

  • assembly reload in scene that does not contain objects that has this MB attached makes problem go away

  • In case you are wondering why am I making such a complicated code structure, see attached example. I am trying to write a Hierarchical State Machine Framework, that will be editable in custom editor window and save it into custom asset. Part of this framework is class HFSMState that inherits from State and can have List of another States/HFSMStates (cause it's hierachical)

  • I know that there is already logged issue that resembles my problem http://issuetracker.unity3d.com/issues/recursive-serialization-makes-unity-fail-badly but in my case this one is not caused by any recursion, it's caused just by Array/List recursion. And the sample project is missing. Also it is almost 5 years old, so I was hoping that something might change :)

Link on project

https://www.dropbox.com/s/g8e4l5jc8j9qst4/XinityAiToolTest.zip

Has anyone encountered this error and found a way to deal with it or is it just a 5 year old Unity memory leak bug that no one bother to fix yet?

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

0 Replies

· Add your reply
  • Sort: 

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

20 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

Related Questions

Why does the editor crash whenever I select a certain script in the project or object with the same script attached in the hierarchy? 2 Answers

Serializating a base class array to a prefab 2 Answers

Initialization of Classes Instantiated in an Array in the Inspector 1 Answer

Unable to serialize my list in a Unity Custom Editor script. 1 Answer

Array of arrays = No serialization? 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