A memory overflow situation is rare under the JVM's memory management mechanism. At least I met less, as if I had been in ssh several times when I published the project. Today saw a very simple way to make memory overflow (well, I seem to be dead--! ):
1 Public classinfiniterecursion {2 PublicString toString () {3 return"Infiniterecursion Address:" + This+ "\ n" ;4 }5 Public Static voidMain (string[] args) {6Infiniterecursion demo =Newinfiniterecursion ();7 System.out.println (demo.tostring ());8 }9}
The problem with the above code is the recursive invocation of the ToString method, and when the compiler finds a string with a plus sign followed by an object, it converts the object to a string by default, The method is to invoke the ToString method of the object (note: The Java object must have the ToString method), and then there is infinite recursion.
Exception in thread "main" Java.lang.StackOverflowError
At Java.lang.abstractstringbuilder.<init> (abstractstringbuilder.java:63)
At Java.lang.stringbuilder.<init> (stringbuilder.java:109)
At Test. Infiniterecursion.tostring (Infiniterecursion.java:6)
At Java.lang.String.valueOf (string.java:2854)
At Java.lang.StringBuilder.append (stringbuilder.java:128)
At Test. Infiniterecursion.tostring (Infiniterecursion.java:6)
.......
What do we have artifice play bad JVM, to share a bit ~ ~ ~
Play the bad JVM very simple--tostring recursive call