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
3
Question by Piesk · Oct 19, 2013 at 10:52 AM · listcollectiongarbage

Garbage collection

Hey guys, this is a real nooby question but then I am essentially a nooby programmer. With respects to garbage collection within unity, as I currently understand it, unity will handle any garbage collection after a new scene has been loaded. That is to say once you load a scene all memory use from the previous scene will be freed up. But, if I am making frequent use of large lists etc within the current scene, do I need to make sure I go through the code using list.Clear() after I no longer need it?

I'm pretty sure this is fundamental basic programming knowledge but our tutors didn't even touch on garbage collection =/.

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

2 Replies

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

Answer by kaushik-d · Oct 19, 2013 at 05:53 PM

If your lists contain GameObjects that are de-activated and won't be needed further in the game, you should destroy those GameObjects (using Destroy()) before clearing your list. If they are references to active objects, clearing these lists wouldn't really help in terms of memory - the instances of these objects in your list will be probably much bigger than the references to them.

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
avatar image
2

Answer by Eric5h5 · Oct 19, 2013 at 06:16 PM

Garbage collection only works on Mono variables (ints, floats, etc.), which includes lists and arrays. Unity objects (GameObject, Texture2D, etc.) are not part of Mono and are not garbage collected. Loading a new level will destroy all Unity objects and call Resources.UnloadUnusedAssets, which you can also call manually if needed.

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 Piesk · Oct 22, 2013 at 11:13 AM 0
Share

thanks both for your answers, I appreciate the help =)

avatar image jeff-smith · Sep 27, 2014 at 03:30 PM 0
Share

To add to Eric's response, be aware of the fact that large $$anonymous$$ono arrays are not garbage collected: http://answers.unity3d.com/questions/225460/big-arrays-are-never-garbage-collected-why.html

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

16 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

Related Questions

A node in a childnode? 1 Answer

garbage collection fix 0 Answers

Collections don't work! 1 Answer

Accessing value from dict allocates 28 bytes 0 Answers

Instantiate/Destroy Garbage Collection advice 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