0
votes

I am debating whether to put static constants that will be accessed throughout instances of a specific class within that class, or in a separate utility class that will be composed only of static constants but will never actually have any instances.

Is additional hardware space allocated for static variables every time a new instance of a class is created?

1

1 Answers

4
votes

Constants are a great semantic tool that conveys to other developers that this is a common, runtime unchanging, value. You should definitely use them if that's what you need.

Performance-wise, it's possible that they are stored with the class definition, but I'm not sure (it's been too long since I was working with the AVM). However, it shouldn't matter. Unless you are creating millions of instances of this class, what you are describing is a micro-optimization and will have zero impact on the performance or memory usage of your app.