21

I'm using IntelliJ IDEA 8 for debugging some Java, but this question could probably apply to all Java debuggers. In the list of variables, they are displayed as:

myVariable = {some.package.SomeClass@12345}

I am curious about the number that comes after the class name. What is the number exactly? Would two variables have the same number if it is the same underlying object that is being referred to?

Thanks in advance.

Jon Onstott
  • 13,499
  • 16
  • 80
  • 133

1 Answers1

19

That is objectId reported by the JVM, for details please see the JDWP specification.

Uniquely identifies an object in the target VM. A particular object will be identified by exactly one objectID in JDWP commands and replies throughout its lifetime (or until the objectID is explicitly disposed). An ObjectID is not reused to identify a different object unless it has been explicitly disposed, regardless of whether the referenced object has been garbage collected. An objectID of 0 represents a null object. Note that the existence of an object ID does not prevent the garbage collection of the object. Any attempt to access a a garbage collected object with its object ID will result in the INVALID_OBJECT error code. Garbage collection can be disabled with the DisableCollection command, but it is not usually necessary to do so.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • 1
    The JDWP objectID is somewhat useless, because we do not have access to it from within our code. The System.identityCashCode() of the object would be much more useful. That's because quite often we have an object A which contains a reference to an object B, and in the toString() of object A we can include the identity hashcode of object B, but then we look through the variables / watches / etc for an object B with that identity hashcode and we cannot find it, because IntelliJ IDEA is not reporting it by identity hashcode. – Mike Nakis Nov 18 '16 at 06:56
  • The same applies to logging: quite often we log references to objects; one easy and reliable way to log an instance of an object is to log its identityHashCode. But again, IntelliJ IDEA makes it impossible to verify whether an object whose reference is in the log is the same as a reference that appears in variables, because I can only log an identityHashCode, but IntelliJ IDEA shows JDWP objectIDs. – Mike Nakis Nov 18 '16 at 22:04
  • @MikeNakis you can open a ticket for that in https://youtrack.jetbrains.com/ – toolforger Oct 14 '22 at 08:35