4

As the question says, how much memory is used for a reference to an Object in the Java Programming Language?

Please, if you have a trusted source is better.

Thanks a lot!

santiagobasulto
  • 11,320
  • 11
  • 64
  • 88
  • 1
    Duplicate of http://stackoverflow.com/questions/981073/how-big-is-an-object-reference-in-java-and-precisely-what-information-does-it-con – khachik Dec 17 '10 at 19:37
  • @khachik thanks! I've been looking, but didn't found it. Anyway, i think that dty an the other guys wrote about interesting things that are not present in the other question. – santiagobasulto Dec 17 '10 at 20:13

1 Answers1

7

It's not specified by the language or JVM spec. However, it's generally accepted that any sane implementation will be 4 bytes on a 32-bit machines and between 4 and 8 bytes (depending on compressed pointer settings, etc.) on a 64-bit machine.

dty
  • 18,795
  • 6
  • 56
  • 82
  • A referencer also implies a referee, the object referred to takes at least 16 bytes in Sun Java 6 and is a multiple of 8 bytes in size. – Peter Lawrey Dec 17 '10 at 19:39
  • Yes but two references does not imply two referees ;-) – aioobe Dec 17 '10 at 19:44
  • 2
    @aioobe, true, they have to be counted separately, but in the simplest cases they are not. A null reference doesn't use any additional memory. – Peter Lawrey Dec 17 '10 at 19:50