当前位置: 代码迷 >> J2SE >> 读入数据总是超内存是神马状况。该怎么解决
  详细解决方案

读入数据总是超内存是神马状况。该怎么解决

热度:88   发布时间:2016-04-24 00:56:40.0
读入数据总是超内存是神马状况。。。
这样一个数据结构:
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]); 试试
  相关解决方案