• 2004-10-10

    OutOfMemoryException When Redeploying

    版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
    http://debiannotes.blogbus.com/logs/435000.html

    ! Why Do I Get an {{OutOfMemoryException}} after Redeploying My Application Several Times ?

    Sun's Java virtual machine creates a so called [Permanent Generation|PermanentGeneration] in their memory heap where they store reflective data about the current runtime. In practice this usually means instances of {{java.lang.Class}} and {{java.lang.reflect.*}} classes.

    When you redeploy applications in JBoss, this always means creating a new classloader (there's currently no way to ''unload'' a loaded class from the classloader although in the upcoming JDK 1.5 there is now a way to ''redefine'' an existing class definition). So when you're heavily redeploying your application, or you have an exceptionally large application it is possible to generate so many instances of reflection objects that the permanent generation is exhausted. If the old instances are not properly being released (in theory they ''should'' but all software has bugs) or all existing instances are still actually needed, the garbage collector will fail to allocate space for the new deployment in the permanent generation and reports an {{OutOfMemoryException}}.

    This can happen quite easily if the default memory configuration of the virtual machine has not been optimized for applications that do a lot of dynamic classloading (or dynamic class generation). To work around the {{{OutOfMemoryException}}} you need to configure the JVM with a larger permanent generation.

    On Sun JVM (1.3.1 and above) this can be done by adding {{-XX:MaxPermSize=128m}} switch on the command line where the JVM is started. This initializes the JVM heap to have a permanent generation size of 128 megabytes.

     

    * [Resizing Permanent Generation on Sun JVM|PermanentGeneration]
    * [Tuning Garbage Collector in Sun 1.4.2 Java Virtual Machine|http://java.sun.com/docs/hotspot/gc1.4.2/]
    * [Frequently Asked Questions about Garbage Collection in the Hotspot Java Virtual Machine|http://java.sun.com/docs/hotspot/gc1.4.2/faq.html]


    历史上的今天:


    收藏到:Del.icio.us