Eclipse: Debugging & inspection of variables causes com.sun.jdi.ObjectCollectedException
Solution 1
Right click the variable, then click "Show Logical Structure", uncheck any collection.
Solution 2
While execution of your code is stopped at a breakpoint:
- Right-click the variable in the
Variables
pane - Clicking on the collections (such as the Array in the image below) will uncheck them
- Now you can inspect the variable
Solution 3
This bug has been fixed in Eclipse 4.18
https://www.eclipse.org/eclipse/news/4.18/jdt.php
Stabilized logical structures in Variables view with active GC
The Debug view no longer breaks when logical structures are shown while the application's garbage collector is active (com.sun.jdi.ObjectCollectedException occurred while retrieving value).
Related videos on Youtube
LeO
Updated on September 16, 2022Comments
-
LeO over 1 year
I debug my program and add here and there a breakpoint. After a stop I want to inspect some of the variables and get sometimes a
com.sun.jdi.ObjectCollectedException
. After searching in different sources I figured out that most likely the object was Garbage Collected. Clicking here and there I could retrieve my object by nevertheless in theVariables
view I cannot inspect the variable.-vmargs -Dosgi.requiredJavaVersion=1.8 [email protected]/eclipse-workspace -XX:+UseG1GC -XX:+UseStringDeduplication --add-modules=ALL-SYSTEM -Dosgi.requiredJavaVersion=1.8 -Xms512m -Xmx4096m --add-modules=ALL-SYSTEM
I'm running under Linux/OpenSuSe with OpenJDK 1.8.0_151. Any hints how to avoid that kind of GC problems? Is this some kind of setting in the IDE?
-
LMC about 6 yearsIf the object was garbage collected you are inspecting it at the wrong place, the object is alive before that breakpoint.
-
LeO about 6 yearsYeah, but after a while keeping the editor open the object cannot be inspected any further. Therefore I assume its GCed
-
Jeremy Bunn over 5 yearsTry this fix: stackoverflow.com/a/49003027/2733353
-
-
M46 almost 5 yearsWorks for me but I don't understand why?
-
javaPlease42 over 4 yearsNote: The variable that you right click must be a collection and not an Object.