public static void searchForChains(Synset source,Synset target,ArrayList<ChainNode> inherit)
{
if(inherit.size() < max+1)
{
try
{
ArrayList<ChainNode> temp = (ArrayList<ChainNode>)inherit.clone(); PointerTargetNodeList list = PointerUtils.getInstance().getDirectHypernyms(source);
if(0 != list.size())
{
searchForChain(list,target,temp,1);
} list = PointerUtils.getInstance().getDirectHyponyms(source);
if(0 != list.size())
{
searchForChain(list,target,temp,2);
} list = PointerUtils.getInstance().getHolonyms(source);
if(0 != list.size())
{
searchForChain(list,target,temp,3);
} list = PointerUtils.getInstance().getMeronyms(source);
if(0 != list.size())
{
searchForChain(list,target,temp,4);
}
inherit = null;
list = null;
}
catch(JWNLException e)
{
e.printStackTrace();
}
}
else
{
inherit = null;
return;
}
}
public static void searchForChain(PointerTargetNodeList list,Synset target,ArrayList<ChainNode> inherit,int type)
{
for(Iterator it = list.iterator();it.hasNext();)
{
PointerTargetNode Node = (PointerTargetNode)it.next();
if(!target.equals(Node.getSynset()))
{
if(!Circle.hasCircle(inherit,Node.getSynset()))
{
ArrayList<ChainNode> temp = (ArrayList<ChainNode>)inherit.clone();
switch(type)
{
case 1:
temp.add(new ChainNode(Node.getSynset(),new StringBuffer("hypernym")));
break;
case 2:
temp.add(new ChainNode(Node.getSynset(),new StringBuffer("hyponym")));
break;
case 3:
temp.add(new ChainNode(Node.getSynset(),new StringBuffer("holonym")));
break;
case 4:
temp.add(new ChainNode(Node.getSynset(),new StringBuffer("meronym")));
break;
default:
break;
}
searchForChains(Node.getSynset(),target,temp);
Node = null;
temp = null; }
else
{
inherit = null;
return;
}
}
else
{
switch(type)
{
case 1:
inherit.add(new ChainNode(Node.getSynset(),new StringBuffer("hypernym")));
break;
case 2:
inherit.add(new ChainNode(Node.getSynset(),new StringBuffer("hyponym")));
break;
case 3:
inherit.add(new ChainNode(Node.getSynset(),new StringBuffer("holonym")));
break;
case 4:
inherit.add(new ChainNode(Node.getSynset(),new StringBuffer("meronym")));
break;
default:
break;
}
Chains.add(inherit);
return;
}
}
}郁闷了啊,产生内存不够的堆错误了啊,怎么都解决不了

解决方案 »

  1.   

    如果没有无限递归的话,那就只有
    1 修改你的算法
    2 增加JVM的可用内存  -Xms 256m -Xmx512m
      

  2.   

    无限循环,用Static做全局对象的保存吧
    尽量早的把对象的引用释放掉否则,创建了那么多长期引用对象,不溢出才怪
      

  3.   

    如果你实在找不出来哪里内存溢出了,可以用Jprofiler进行测试,强大的性能测试软件,可以按对象,方法调用等各种方式统计你的内存,CPU消耗情况,作为对比, 还可以跟踪每一个对象和线程,看到底是因为哪里的引用而导致没有被垃圾回收.我前段时间那个spider程序被java heap space,out of memory困绕了很久,最后研究了一个星期的Jprofiler,终于解决了