I was trying to save one of the class object to a File using ObjectOutputStream. When My object grows with the size I get the below error otherwise it is all good.
Exception in thread "Thread-2" java.lang.OutOfMemoryError: Java heap space at java.io.ObjectOutputStream$HandleTable.growEntries(ObjectOutputStream.java:2308)
My code looks like this:
try {
FileOutputStream fout = new FileOutputStream("D:\\out.dat");
ObjectOutputStream os = new ObjectOutputStream(fout);
os.writeObject(this.obj); // Writing object to a File
os.close();
fout.close();
os=null;
fout=null;
} catch (Exception e) {
e.printStackTrace();
}
Please suggest me how can I resolve this? Any alternate approach to achieve the same?
this.objthat you want to write it?!