MATLAB: Do I receive an OutofMemory error: PermGen space when calling MATLAB 7.0.4 (R14SP2) from Java

databasedberrorsjavajava.lang.outofmemoryerrorjava.optsjvmMATLABoutofmemorypermgenspacetoolbox

I receive the following error when I call MATLAB from my Java program:
Java exception occurred:
java.lang.OutOfMemoryError: PermGen space

Best Answer

This is expected behavior.
The PermSpace holds objects describing classes and methods of the Permanent Generation. Applications with large code-base can quickly fill up this segment of the heap which will cause java.lang.OutOfMemoryError: PermGen errors
For more information on garbage collection in Java, you may want to look at the item entitled:
Tuning Garbage Collection with the 1.4.2 Java Virtual Machine
<http://java.sun.com/docs/hotspot/gc1.4.2/>
To increase the Permanent generation heap space, create a java.opts file in the $MATLAB/bin/$ARCH
(Where $MATLAB is your root MATLAB directory and $ARCH is your architecture.)
or in the current directory when you start MATLAB, containing the following command:
-XX:MaxPermSize=128M
This will set the maximum permanent generation size of 128M on Sun JVM when starting the virtual machine. Be sure not to set the java heap bigger than the physical memory of the system.
NOTE: MathWorks has not tested MATLAB with any settings other than our default configuration.