2012-12-14 2 views
0

다른 루프에 중첩 된 2 개의 루프를 포함하는 내 프로그램을 실행할 때 OutOfMemoryError java heap space.i가 1 주일 동안 해결책을 찾고 있었지만 result.i는 문제가 있음을 알고 있습니다. 인스턴스를 생성 할 때마다 많은 시간이 걸리므로 메모리 누수가 발생합니다. 메모리 크기를 늘리려고했지만 충분하지 않습니다. 내 질문은 어떻게 excution.this에 많은 메모리를 사용하지 않고 동일한 프로그램을 개발할 수 있습니다 내 programm이야.java heap space

public String getAllActionsJson(){ 
     //liste des actions de la table action 
     List<Action> actions = actionService.getAllActions(); 
     //liste onglets de la table typeAction 
     List<TypeAction> typesActions=actionService.getTypeActions(); 
     ActionNoeudJson actionRacine = null; 
     ActionNoeudJson actionFeuille = null; 
     List<ActionNoeudJson> listeFilles = null; 
     for(int i=0;i<typesActions.size();i++) 
     { 
      listeFilles = new ArrayList<ActionNoeudJson>(); 
      actionRacine=new ActionNoeudJson(); 
      actionRacine.setId(typesActions.get(i).getId()); 
      actionRacine.setText(typesActions.get(i).getLibelle()); 
      for(int j=0;j<actions.size();j++) 
      { 
       //si le type de l'action est le meme que le type de l'onglet 
       //on affecte actionFeuille à la racine courante(onglet approprié) 
       if(typesActions.get(i).getId()==actions.get(j).getTypeAction().getId()) 
       { 
        actionFeuille = new ActionNoeudJson(); 
        actionFeuille.setId(actions.get(j).getId()); 
        actionFeuille.setText(actions.get(j).getLibelle()); 
        actionFeuille.setIconCls("icon-tip"); 
        listeFilles.add(actionFeuille); 
        actionRacine.setChildren(listeFilles); 
       } 
      } 
      listeActions.add(actionRacine); 

     } 
     return ActionSupport.SUCCESS; 

    } 
+1

아마도 메모리 누수가있을 것입니다. 루프에서 사용한 후에 재사용 된 변수를 null로 설정하려고합니다. 나는 이것이 당신의 문제인지 잘 모르겠지만 시도 할 만하다. 구글 메모리 누수를 해결하는 방법을 구글 검색 – Codeguy007

+0

나는 일주일 동안 유일한 주어진 솔루션은 실행 구성에서 명령 -Xmx512m로 메모리 크기를 늘리고있다하지만 그 증상이 아닌 질병에 치료를 봤는데 이 알고리즘을 내 질문에 공유하고 있습니다 –

+0

https://www.google.ca/search?q=how+to+debug+a+java+memory+leak&aq=f&oq=how+to+debug+a+java+ memory + leak & aqs = chrome.0.57j0j62l3.15404 & sugexp = chrome, mod = 12 & sourceid = chrome & ie = UTF-8 – Codeguy007

답변

0

이것은 알고리즘 분석이라고하는 주제의 연구 영역입니다. 적어도 Big O Notation에 익숙하지 않은 경우 알고리즘을 개선하는 방법을 이해하는 것이 매우 어려울 것입니다.

표기법을 이해하고 기본 분석을 수행 할 수있는 경우 가장 많은 양의 메모리를 사용하는 코드 부분을 찾아서 먼저 최적화 해보십시오. 예를 들어, 실제로 계산에 필요하지 않은 데이터가 있습니다.

모든 유형의 모든 작업에 대해 일부 값을 설정하려고하는 것으로 보입니다. 그걸 덩어리로 만드는 건 어때? 같은 시간에 모든 것을 메모리에 갖지 않도록 작업을 분할하십시오. 그런 다음 점진적으로 일련의 작업을 작성한 다음 배열의 모든 요소에 대해 listeActions.add()에 대해 단일 작업을 수행하십시오.