📜 ⬆️ ⬇️

Errors out of perm gen space in Java programs

Often when redrawn java applications, an error occurs OutOfMemory: PermGenSpace. Let's see what it is, why it happens, and how to deal with it.

What does this mistake mean? When running a Java virtual machine, application classes are stored in a special area of ​​memory called the permanent generation. This was done on purpose, because classes are loaded / rendered relatively rarely, so the garbage collector does not need to be called for them very often. There is a misconception that classes from there are not unloaded, as it may seem from the name. This is not true, you can make sure that the classes are unloaded by connecting to the java process using the JConsole utility.

Let's now consider the reasons for which these problems arise. The most aborted of them are errors in the program. Somewhere the thread running under the old version of the application may hang, and for some reason I don’t kill, some listener could not be deleted and so on. To deal with such problems is relatively simple: you need to find someone who keeps references to old classes with the help of a profiler. Eclipse Memory Analyzer is especially good here: www.eclipse.org/mat It easily maintains applications occupying about a gigabyte of memory.
')
Also, in Java, there are some APIs and libraries that lead to class leaks due to obishok. Here: opensource.atlassian.com/confluence/spring/display/DISC/Memory+leak+-+classloader+won't+let+go opensource a list of frequent sources of problems with their solutions.

Often, despite all the tricks, the error still crashes, while in the profiler everything looks good: none of the application code refers to the classes, but for some reason the classes are not compiled. Here, the problem most likely consists in the particular implementation of the server virtual machine, due to which some classes will be filled up before the classes are assembled. This problem has long been known, and is one of the most popular problems in the Java Bug Parade: bugs.sun.com/bugdatabase/view_bug.do?bug_id=4957990 Despite its popularity, and the fact that the bug has been known for 9 years, Sun has put it low priority, so the chances that it will soon fix a little.

How can you deal with it? First, you can run the application under a client virtual machine, using the –client switch. But this method does not work on 64-bit systems, where there are only server-side virtual machines. Another option is to experimentally pick the value of MaxPermSize.

Source: https://habr.com/ru/post/65898/


All Articles