[英]Java: not enough heap space when reading serialized file
In one method I create a serialized file from an adjacency list which I'm trying to read in another method as follows: 在一种方法中,我从邻接列表创建一个序列化文件,该列表试图在另一种方法中读取,如下所示:
Map<Integer, List<Integer>> adj;
int[] count;
int N;
ArrayList<Double> weights;
try (
ObjectInputStream input1 = new ObjectInputStream(new FileInputStream("GIRGnew5adj.ser"));
){
N = (int)input2.readObject();
adj = (Map<Integer, List<Integer>>)input1.readObject();
Now, while the file itself is around 500MB large I get an OOM:Java Heap Space error even when I increase my heapsize to 2000MB but then again it works for a heap of 6000MB. 现在,尽管文件本身大约有500MB,但即使我将堆大小增加到2000MB,我也会收到一个OOM:Java堆空间错误 ,但是对于6000MB的堆,它仍然可以工作。
I wonder, how come does the same information take so much more space in memory than on hard disk? 我想知道,为什么相同的信息在内存中比在硬盘上占用更多的空间?
This is a very rough path of what happens. 这是发生的事情的很粗略的路径。 Just so you have an idea what the computer does when load the file. 如此您便知道了加载文件时计算机的功能。 This will not be 100% accurate and actual process might differ, be more efficient, this is just for puposes as giving an isight why the computer needs so much ram. 这将不是100%准确,实际过程可能会有所不同,效率会更高,这只是出于目的,为什么计算机需要那么多的内存。
So a total tally of rougly 3650.01mb. 因此总计3650.01mb。
Then the garbage collector comes by at some point and cleans up the mess and you're left with about 400mb. 然后,垃圾收集器会在某个时候到达并清理垃圾,剩下的空间约为400mb。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.