Openfire Java Out of Memory Error – Any solutions?-Collection of common programming errors

I have huge problem with openfire crashing every now and then because of the lack of memory. In java log i have following error log. however problems are

  1. Openfire is 32 bit and i cant run it as 64 bit.
  2. Because its only 32 bit max memory i can give to the openfire is 4GB.
  3. My system is very powerful with 32 GB RAM so i cant increase any more
  4. Only max 100 users are using the openfire but still cant seems to handle it
  5. I have run a cron jobs every 5 min to monitor this service and restart every now and then

any solutions on how to optimize open-fire for memory usage and stop it crashing ?

error log as below

#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (malloc) failed to allocate 140 bytes for CHeapObj-new
# Possible reasons:
#   The system is out of physical RAM or swap space
#   In 32 bit mode, the process size limit was hit
# Possible solutions:
#   Reduce memory load on the system
#   Increase physical memory or swap space
#   Check if swap backing store is full
#   Use 64 bit Java on a 64 bit OS
#   Decrease Java heap size (-Xmx/-Xms)
#   Decrease number of Java threads
#   Decrease Java thread stack sizes (-Xss)
#   Set larger code cache with -XX:ReservedCodeCacheSize=
# This output file may be truncated or incomplete.
#
#  Out of Memory Error (allocation.inline.hpp:44), pid=31239, tid=2735213424
#
# JRE version: 6.0_41-b02
# Java VM: Java HotSpot(TM) Server VM (20.14-b01 mixed mode linux-x86 )

---------------  T H R E A D  ---------------

Current thread (0xad2c7000):  JavaThread "Jetty-QTP-AdminConsole-16012" [_thread_in_vm, id=21077, stack(0xa3030000,0xa3081000)]

Stack: [0xa3030000,0xa3081000],  sp=0xa307f3d4,  free space=316k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0x727990]
  1. Openfire is written in java and is not 32-bit specific. If you use a 64bit jvm, it will run in 64 bit mode and you can give it as much ram as you have. Try installing a 64bit jvm/jre