tags:

views:

31

answers:

1

How are enums handled when it comes to the heap, memory, and when an enum type instance is created? If I've got an enum with fifty field constants, then do I have fifty objects on the heap representing that enum type (when accessed), and are there performance concerns?

+2  A: 

The first time the type is accessed and it gets initialized, a new object is created for each value. However, unless you have a huge number of instance fields in the enum, each object will be very small. I'd be very surprised to see a situation in which this was a real performance concern unless you were on a massively constrained device.

Jon Skeet