0

I am doing an online course at the moment and the lecturer says that in Java the memory overhead of a class is 32 bytes, but an inner class is only 16 bytes. Why is this?

More Than Five
  • 9,959
  • 21
  • 77
  • 127
  • 7
    Ask your lecturer? What the memory overhead of an object is, depends on the JVM implementation. What you say is not true in general for any arbitrary JVM implementation. – Jesper Apr 11 '13 at 10:44
  • You may want to have a look at the following thread: http://stackoverflow.com/questions/258120/what-is-the-memory-consumption-of-an-object-in-java and what does overhead mean in this instance? Because it does depend on the JVM being used. An Object takes 8 bytes. – blackpanther Apr 11 '13 at 10:47
  • 1
    @Jesper It's online. Robert Sedgewick. – More Than Five Apr 11 '13 at 10:47
  • 1
    Since once it has been compiled an inner class ist just a specially nanmed class (outer$inner) I very mouch doubt that this is true. – Christian Seifert Apr 11 '13 at 10:50
  • @perdian that's what I thought – More Than Five Apr 11 '13 at 10:51

1 Answers1

2

The details are JVM-specific. However, the numbers given look implausible: An inner class requires a reference to the enclosing instance of the outer class, thereby requiring higher overhead than a top-level class.

NPE
  • 486,780
  • 108
  • 951
  • 1,012