java.lang.OutOfMemoryError: Java heap space


I’m running into this when pulling json from a webservice. Any ideas on what I need to do to correct this?



That’s sort of a generic error, but like it says, you’re running out of heap space. Firstly, is there more to the error message? If so, please include it? Secondly, have you measured your memory usage for the server? if so, what did you find? How big is your heap set to? Have you tried increasing it? And finally, how big is the JSON you’re parsing?

Lucee Error (
Message	java.lang.OutOfMemoryError:Java heap space
Java Stacktrace	lucee.runtime.exp.NativeException: java.lang.OutOfMemoryError:Java heap space
 	at java.util.Arrays.copyOf(
 	at java.lang.AbstractStringBuilder.ensureCapacityInternal(
 	at java.lang.AbstractStringBuilder.append(
 	at java.lang.StringBuffer.append(
 Caused by: java.lang.OutOfMemoryError:Java heap space
 	... 8 more
Timestamp	12/5/17 7:02:39 PM UTC
free -m
             total       used       free     shared    buffers     cached
Mem:           993        920         72          0         24        283
-/+ buffers/cache:        612        381
Swap:            0          0          0
cat /proc/meminfo
MemTotal:        1017324 kB
MemFree:           74224 kB
MemAvailable:     280912 kB
Buffers:           25508 kB
Cached:           290232 kB
SwapCached:            0 kB
Active:           725136 kB
Inactive:         155432 kB
Active(anon):     564832 kB
Inactive(anon):       52 kB
Active(file):     160304 kB
Inactive(file):   155380 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                16 kB
Writeback:             0 kB
AnonPages:        564860 kB
Mapped:            44752 kB
Shmem:                60 kB
Slab:              47712 kB
SReclaimable:      37452 kB
SUnreclaim:        10260 kB
KernelStack:        2368 kB
PageTables:         4080 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:      508660 kB
Committed_AS:     814956 kB
VmallocTotal:   34359738367 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB
AnonHugePages:         0 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:       12288 kB
DirectMap2M:     1036288 kB

In Lucee Admin (top right):


The JVM (Java Virtual Machine) has a heap that is the runtime data area from which memory for all objects are allocated.


Also, the JVM has memory other than the heap, referred to as non-heap memory. It stores all cfc/cfm templates, java classes, interned Strings and meta-data.

Not sure where to adjust heap size?


For Tomcat create a setenv.bat or depending on OS. Do a set JAVA_OPTS=-Xms1024M -Xmx1024M or whatever memory amount you need. You can hover over the HEAP line in Lucee Admin to see what it is defaulting to.


Looks like you’ve got 1GB of total RAM there. I’m assuming you’re running a VM of some sort? Maybe a micro instance on AWS? Either way, 1GB of RAM is fairly sparse and doesn’t leave you a lot of wiggle room. For instance, setting your heap size to 1024MB won’t help you much here because there isn’t going to be that much RAM available anyway.

If you’re on a VM, I’d up the amount of RAM available to that server to at least 2GB since it’s just a Linux server. If you’re on a micro AWS, you may need to go to a bigger instance to get the best performance - especially if you’re digesting large datasets.


– Denny


Ya I’m running a micro instance on AWS T2-micro. Trying to see what I can get away with as far as smallest cost. Do you have any recommendations on what instance type Lucee should really run on?

Thanks for the help.


Selecting the proper sized compute instance depends on a lot of factors - how performant is the code, how many concurrent users are anticipated using that code, how quickly you want the site to respond under load, etc. etc.

Lucee can run just fine under a micro instance, for example, so long as the code is well tuned, there aren’t many concurrent users and you don’t mind it responding slowly under heavy load.

micro can be a good starting point, until you run into issues like you have with outOfMemory errors. This is where FusionReactor can really help by showing usage patterns, slow queries and pages, etc. so you can a) adjust code that is performing poorly and b) determine average load and peak load on the system.

The other alternative is to go up one tier at a time, getting more resources (memory, cpu) as needed through trial and error - not the recommended approach, but if you don’t have/can’t install a trial of/can’t afford a license for FR, it’s the path I’d choose - go up to the next tier where you have more RAM first, since that seems to be where your bottleneck is currently, and give it another go.


– Denny


thanks for the information everyone that was very helpful