Java debugger: Can I "remember" an object reference? Follow
Answered
Is it possible in the debugger to store a reference to an object, so that I can later inspect it, even if it is no longer accessible via any variables in the then-current stackframes?
For example I am currently stopped at a Spring Bean constructor which creates and configures a connection manager. At a completely unrelated breakpoint I'd like to take a peek at that connection manager.
That should be possible, right? I mean I could create a singleton class with a static instance of Map<String, WeakReference<Object>> and use that to store and later reference the object by a name. So the debugger should be able to do it, too, right?
Please sign in to leave a comment.
Sure, first mark the object you need in the debugger tree (name it somehow - xxx for example). Any time after that you can inspect it's value by evaluating xxx_DebugLabel expression in evaluator.
More details here: https://www.jetbrains.com/help/idea/2017.1/setting-labels-to-variables-objects-and-watches.html.
Thanks a lot! That works great.
It is a very well hidden feature, though: I can see no hint of this feature at all in IDEA itself. (Other than the code completion - that you wouldn't try to use if you didn't know that this feature exists.)
An explicit action to show all or specific marked objects would be great!