簡體   English   中英

異常OutOfMemoryError:Java堆空間

[英]Exception OutOfMemoryError: Java heap space

我想保存一個大物件

 public void saveGenes() throws FileNotFoundException, IOException{
        String file = "genes.obj";
        String start = String.format("%tr", new Date());
        System.out.println("Save "+file+"...... "+start+"\n");
        ObjectOutputStream oos = new ObjectOutputStream(new     BufferedOutputStream(new FileOutputStream(file)));
        Genes g = new Genes();
        g=this;
        oos.writeObject(g);
        oos.close();
        String end = String.format("%tr", new Date());
        System.out.println("Save Completed......" + end);
    }

但是我必須在線程“ main”中嘗試此錯誤異常。java.lang.OutOfMemoryError:java.io.ObjectOutputStream $ HandleTable.growEntries(未知源)處的Java堆空間

我使用-Xmx4096M進行了測試,但錯誤不斷出現

您可以嘗試將數據分解為較小的部分,也可以嘗試調用System.gc() ,但是以我的經驗,它什么也沒做。 但是,如果從戰略角度考慮放置它,那么我聽說它是​​可行的。

我不知道發生這種情況的任何具體原因。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM