0

If for example, I had a linked list of nodes. Each having a field referencing the next node. How much memory does this reference (not the next object) take?

E.g if I have:

Class Node
nextNode node;

public Node(node nextNode){
this.nextNode = nextNode;
}

Does the nextNode field take any memory? If I read correctly, the reference takes 4 bytes, but I'm unsure as I find conflicting information. Thanks!

Jskoven
  • 31
  • 1
  • 1
    It isn't specified, but you can expect it to take 8-16 bytes. – user207421 May 16 '22 at 12:19
  • Possible duplicate of https://stackoverflow.com/questions/981073/how-big-is-an-object-reference-in-java-and-precisely-what-information-does-it-co – Robert May 16 '22 at 12:21
  • I think it usually takes twice as much as a pointer on your system. So 64 bits on a 32 bit system, and 128 bits on a 64 bit system. However 64 bit systems have a JVM flag to use (mostly) 32 bit pointers so you can reduce memory usage a lot with that flag. – markspace May 16 '22 at 13:45

0 Answers0