2014-04-11 2 views
-1

while 루프를 무한대로 실행하려면 Java 힙 공간을 얻지 만 메모리를 정리하려면 "시스템 가비지 클리너"를 사용하고 있습니다. 그래서 어떻게이 문제를 해결할 수 있습니다.무한 루프 while java.lang.OutOfMemoryError : Java heap space

try{ 
    while(true){ 
     try{ 
      attach=sample.readMails();   
      System.gc(); 
     } 
     catch (IOException e){ 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
      System.out.println("Error In readMails-->downloads"); 
     } 
    } 
}catch (Exception e){ 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
    System.out.println("Error In Infinite While"); 
} 
+1

의 문서에 따르면, 당신은 왜 루프를 중단하는 조건없이 무한 루프를 실행해야 할 것인가? – anirudh

+2

'readMails()는 무엇을 하는가? – DNA

+1

당신은'System.gc()'를 호출하고 있지만 이것은 GC가 즉시 호출된다는 것을 의미하지는 않습니다. –

답변

0

System.gc은 사용하지 않는 개체에서만 작동합니다. System#gc

Calling the gc method suggests that the Java Virtual Machine expend effort toward recycling unused objects in order to make the memory they currently occupy available for quick reuse.

관련 문제