In C++ and C# when new not able to allocate enought memory it throws exception.
I couldn\'t find any information about new\'s behavior in Java. So what will happen
A little more on OOME.
/*License - LGPL
Recovery from an OutOfMemory Error
The JavaDocs for Error state, in the first sentence..
"An Error is a subclass of Throwable that indicates
serious problems that a reasonable application should
not try to catch."
This advice has led to the fallacy that an OutOfMemoryError
should not be caught and dealt with. But this demo. shows
that it is quite easy to recover to the point of providing
the user with meaningful information, and advice on how to
proceed.
I aim to make my applications 'unreasonable'. ;-)
*/
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import javax.swing.JOptionPane;
import javax.swing.JDialog;
import javax.swing.Timer;
import javax.swing.border.EmptyBorder;
import java.util.ArrayList;
/** A demo. showing recovery from an OutOfMemoryError.
Our options once an OOME is encountered are relatively
few, but we can still warn the end user and provide
advice on how to correct the problem.
@author Andrew Thompson */
public class MemoryRecoveryTest {
public static void main(String[] args) {
// reserve a buffer of memory
byte[] buffer = new byte[2^10];
ArrayList