Java debugger: Can I "remember" an object reference?

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?

 

3 comments
Comment actions Permalink

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.

0
Comment actions Permalink

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!

0

Please sign in to leave a comment.