ã¯ã©ã¹ãã¼ããªã¼ã¯ã¨ãã¼ããã³ã
Java EE ã使ã£ã¦ãã人ãªãå¤ãã®äººãééããã¯ã©ã¹ãã¼ããªã¼ã¯ãEclipseãªã©ã®IDEã§ããããããã¤ããªããéçºãã¦ããã¨ãçªç¶APãµã¼ãããå¿çããªããªã£ãããjava.lang.OutOfMemory : PermGen
ãåºåããããããã
åå ã«ã¤ãã¦ã¯nekopããã®ã¹ã©ã¤ããyamadanããã®ããã°ã«ç´¹ä»ããã¦ããã®ã§ãããã§ã¯ã¯ã©ã¹ãã¼ããªã¼ã¯ãæå ã§åç¾ããã¦ã¿ã¦ãã©ã®ãããªãã¼ããã³ãã«ãªããç´¹ä»ããã
ãã¼ããã³ãã®è§£æã«ã¯EclipseMemoryAnalyzer(MAT)ã使ãã
1. Duplicate Classes ã確èªãã
ã¯ã©ã¹ãã¼ããªã¼ã¯ãçºçãã¦ããç¶æ³ã§ã¯ãåä¸ã®ã¯ã©ã¹ãç°ãªãã¯ã©ã¹ãã¼ããããã¼ãããã¦ããäºè±¡ãèµ·ãã£ã¦ãããMATã§ã¯éè¤ã¯ã©ã¹ãã¼ãã®ä¸è¦§ã表示ããæ©è½ãããããã1ã¯ãªãã¯ã§ç¢ºèªã§ããã
Tomcatã®å ´å
Tomcat(8.0.5)ã¯WARãã¨ã«org.apache.catalina.loader.WebappClassLoaderã«ãã£ã¦ãWARãã¡ã¤ã«å ã«å«ã¾ããã¯ã©ã¹ããã¼ããããã¯ã©ã¹ãã¼ããªã¼ã¯ãçºçãã¦ããã¨ãåãã¯ã©ã¹ãæã¤WARã¯1ã¤ãããããã¤ãã¦ããªãã¯ããªã®ã«ãè¤æ°ã®ã¯ã©ã¹ãã¼ãã«ãã£ã¦èªã¿è¾¼ã¾ãã¦ãããã¨ããããã
2. Paths to GC Roots ã®ç¢ºèª
ããã¾ã§ã§ã¯ã©ã¹ãã¼ããªã¼ã¯ãã©ãããèå¥ããããåå ãããããªããä½ãåå ã§GCããã¦ããªããã¯ã対象ã®ã¯ã©ã¹ãã¼ãã¤ã³ã¹ã¿ã³ã¹ãé¸æãã¦å³ã¯ãªãã¯ããPath to GC Rootsã確èªããã
以ä¸ã®ããã«ãTomcatã®ãã¼ã«ããã¦ããTaskThreadãæã¤ThreadLocalããåç §ããã¦GCãããªããã¨ããããã
WildFly8ã§ãåæ§ã«ããã¼ã«ããã¦ããã¹ã¬ããã®ThreadLocalããåç §ããã¦GCãããªããã¨ããããã
ThreadLocalã«ã¦ã¼ã¶æ
å ±ãªã©ãªã¯ã¨ã¹ãå
±éã§ä½¿ããããã¼ã¿ãæ ¼ç´ããå¾ãThreadLocal.remove()
ãå®è¡ããã«APãµã¼ãã®ãã¼ã«ã«ã¹ã¬ãããè¿ããããããã¯ã©ã¹ãã¼ããªã¼ã¯ã®åå ä¾ã示ãããã¼ããã³ãã§ãããServletFilterãªã©ã使ã£ã¦ã¿ã¹ã¯ã¹ã¬ãããAPãµã¼ãã®ãã¼ã«ã«è¿ãåã«ThreadLocal.remove()ã§æé¤ãããã¨ã大åã§ãã
追è¨
第åå æ¸è°·Javaã§ã¯ã©ã¹ãã¼ããªã¼ã¯ã«ã¤ãã¦ã話ãã¾ãã: