I have 16GB of total DDR4 RAM in my PC. I have dedicated 8GB to the pack and also have 64 bit Java installed. For some reason (it hasn't happened recently), but my pack will crash and the error report says 'OutOfMemory'. This doesn't make any sense if I have 16GB total and only 8GB dedicated. I also should note that at times I can't even launch the pack if I have 10GB+ dedicated. it just crashes instantly with the same error 'OutOfMemory'.
Native memory allocation (malloc) failed to allocate 2265552 bytes for Chunk::new
# The system is out of physical RAM or swap space
In other words, your OS can't allocate any more memory because there isn't any left - one cause being allocating too much memory to Java, as mentioned in the solutions - allocating more, which is the first thing people do or suggest when they see "out of memory", will only make things worse (allocating memory will only help if the error is "OutOfMemoryError: Java heap space"):
# Reduce memory load on the system
# Increase physical memory or swap space
# Check if swap backing store is full
# Decrease Java heap size (-Xmx/-Xms)
# Decrease number of Java threads
# Decrease Java thread stack sizes (-Xss)
# Set larger code cache with -XX:ReservedCodeCacheSize=
In particular, you are out of swap space, with only 6 MB left even if you still have 7 GB of physical memory left (19.5 GB of swap may indicate that you were using well in excess of the available physical memory at the time of the crash and the 7 GB of free physical memory is simply due to it having just been deallocated while swap hadn't been freed yet):
Note that Minecraft uses more memory than what you allocate to Java, sometimes even double or more (for example, OpenGL uses native memory and mods may greatly inflate this due to the number of textures/models they add), which is why it is generally suggested to never allocate more than half your free system memory (this means less than 8 GB for a 16 GB machine as it is based on free memory, not the total).