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 /
  • Help Room /
This question was closed Sep 17, 2016 at 02:31 PM by febucci for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by febucci · Sep 15, 2016 at 01:32 PM · arrayarraysmemorymemory usageempty

Does empty array declaration take memory?

I have a large "Monster Manager" script, wich has lot of public arrays (all empty) If I select an enumerator like "Shoot", I have to use the Bullets array (gameobject). The script uses coroutines based on the enumerator, it won't check something from other arrays.

So my queston is, do i kill my game doing this way ? Because my game will have lot of monster each scene, but each monsters has a lot of empty arrays. They're all empy and their size won't be changed in the script, so does unity consider them in memory or not?

Comment
Add comment · Show 4
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 Owen-Reynolds · Sep 15, 2016 at 02:57 PM 1
Share

If they do, how much can they take? And if you want to leave them null to save space, ask yourself if checking for null all the time is more of a waste.

Google "premature optimization" for why you shouldn't even worry about this.

avatar image febucci Owen-Reynolds · Sep 17, 2016 at 12:48 PM 0
Share

Thank you, but I already have my game. I have the full "master" script but I have lot of empty arrays, and I don't know how Unity handles them.

avatar image JedBeryll febucci · Sep 17, 2016 at 02:22 PM 1
Share

Arrays will take up space for the references at least, even if empty. But you really shouldn't worry about this because even if you have 1000 references it will only use up like 4 kilobytes.

Show more comments

1 Reply

  • Sort: 
avatar image
2
Best Answer

Answer by JedBeryll · Sep 17, 2016 at 02:30 PM

Arrays will take up space for the references at least, even if empty. But you really shouldn't worry about this because even if you have 1000 references it will only use up like 4 kilobytes.

Comment
Add comment · Show 1 · 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 Owen-Reynolds · Sep 17, 2016 at 04:15 PM 1
Share

?? I'm not reading that as the Q. Obviously int[] A=null; takes some space. But does int[] A=new int[0]; take more? But, of course, the correct answer is as you write: not enough to be worth thinking about.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Why is inserting variables into an array not working? 0 Answers

condition for array of textures 1 Answer

Instantiate players in Photon. Error: Index was outside the bounds of the array. 1 Answer

How to Spawn a Prefab at an already Spawned Prefab's that's from an array at their transform.position? 1 Answer

Convert a square array selection to circular selection 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