- Home /
C# do uninstantiated dictionaries affect memory?
I'm asking there because I can't seem to find an way to formulate my search so that google understands me.
I'm having this class that would be the base of pretty much everything in my game, from bullets to the main character, it allows me to make a pause function.
In this class, in order to make life easier for me, I'm putting much management code, one of the functionalities requires me to plan 2 Dictionaries of List, I don't instantiate them if I don't need them, but admitting I'm having a thousand bullets on the screen (2D bullet hell style for IOS), would there be any impact on performance/memory because of this?
Also, generally, what happens with fields that don't have an instance yet, is there any memory slot allocated to them?
Answer by Wolfram · Jan 10, 2013 at 08:08 PM
If unassigned, these fields will be null, and no memory is allocated. However, if these fields are public class members, and can be displayed in the Inspector (which is true for Lists, fixed arrays, and strings for example), the UnityEditor will automatically initialize them. Otherwise, it stays null.
And of course since it's a reference it will use 4 bytes for the reference itself ;)
You are right of course. I forgot to mention it because it was too obvious for me, but it should of course be part of the answer.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Best way to load assets from AssetBundle? 1 Answer
Changing material color creates a memory leak 1 Answer
constructor called multiple times 1 Answer