这样一个数据结构:
- Java code
public class Feature { String name = new String(); byte[] coords = new byte[128]; // 所有维度的数值}
读入的时候是这样读取的:
int k;
int total = 10000000;
- Java code
while ((tempString = reader.readLine()) != null && i!=total-1) { String[] vector = tempString.split(" "); f[i] = new Feature(); f[i].name = vector[0]; for(int j=0;j<128;j++) { k = Integer.valueOf(vector[j+1]); f[i].coords[j] = (byte)k; } i++; vector = null; }
特地把虚拟机开到了7G内存,但是在读入到600w左右的数据之后就已经超内存了然后运行暴慢!!!
按道理来讲这样一个类开到1000w内存也不应该超过2G啊。。
求问大家这是什么原因呢?><
------解决方案--------------------
你把 f[i].name = vector[0]; 改为 f[i].name = new String(vector[0]); 试试