DEV Community

Discussion on: Ways to create Singletons and the tradeoffs between them

ujaehrig profile image
Ulf Jährig

Methods will still take space in the permanent section of the heap, as classes are still loaded. But this is a one-time cost. But what should be the difference between a single static enum member and a static member in a normal class? IMHO it doesn't matter if the static member is part of an enum or part of a "normal" class. The only advantage of an non-enum is the possibility of lazy initialisation. So my suggestion would probably be more on the line of lazy initialisation required and not on memory consumption.

As Vincent already said, the article above is quite old (and volatile will help), but AFAIK the memory model didn't change and the overall problem is still valid today.