Perm space versus heap space

First, what is the difference between Perm space and heap space (what and how does the JVM choose to use each memory space)?

Secondly, but most importantly, what relation would be recommended for a standard Java application like MVC?

+72
java performance memory-management
Jan 31 '11 at 7:50
source share
3 answers

the heap stores all objects created by your Java program. The contents of the heap are controlled by the garbage collector, which frees memory from the heap when the object is terminated (i.e. when there are no more references to the object.

This is different from stack , which stores primitive types such as int and characters, and usually these are local variables and function return values. This is not garbage collection.

perm space refers to a special part of the heap. See This SO Answer for an explanation: What is perm space?

+75
Jan 31 2018-11-11T00:
source share

Personally, I don't consider PermGen a special part of the heap.

I would rather think of the heap as a memory area for storing instances of an object, and PermGen as a region for storing class definitions. As a result, the heap life cycle is tied to the application, and the PermGen life cycle is tied to the JVM.

One of the best examples of why an application and its JVM can have a different life cycle in a Java EE container. On the application server, applications can be deployed and deployed without restarting the server. During undeployment (or redistribution) it is easy to free all instances of the object, i.e. empty space, but it’s rather difficult to remove all classes loaded by this application from PermGen, because some of the classes can still reference the JVM.

One such case is a driver leak . When the application is deployed, the JDBC driver is downloaded and registered using the DriverManager. When this application is not deployed, DriverManager lives and contains a link to the driver, its original class loader and all the loaders of this class. The result is a memory leak in PermGen, but this is not an application memory management error.

True, the JVM, like JRocket, does not have PermGen at all, everything is stored on the heap. Only in this context can you call PermGen the “special part” of the heap. Even then, we should still consider PermGen and the bunch differently, as they have a completely different purpose, and they have very different types of memory leaks.

Update . In Oracle, JDK 8 PermGen is replaced by and is now officially part of the heap. We no longer need to configure PermGen.

+33
Jun 03 '13 at 3:13
source share

You cannot specify allocated memory names on the heap.

This means that int x (its name) is allocated on the stack. You can reach the pointer by its name, so the pointer is on the stack. You cannot reach an object by its name because it does not have a name. Accees to the (unnamed) object must be on the pointer.

0
Jan 29 '16 at 12:14
source share



All Articles