日期:2014-05-20  浏览次数:20724 次

急啊,如何解决JAVA HEAP SPACE错误?
Java code

    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;
            }
        }
    }