9

'OutOfMemoryError': Usually, this error is thrown when there is insufficient space to allocate an object in the Java heap.

GC (Allocation Failure): Allocation Failure” means that there is an allocation request that is bigger than the available space in young generation.

Does this mean Allocation Failure will be thrown when Young generation memory is full (Minor GC) and "OutOfMemoryError" is thrown in full GC?

user3024119
  • 131
  • 1
  • 2
  • 8

2 Answers2

9

These could become related as far as I can tell; but they are entirely different things.

OutOfMemory is an error you can not recover from - the JVM will die at this point.

GC (Allocation Failure): Allocation Failure is the reason why GC will kick in (and do a minor collection). At this point some things might happen, like: enough space is freed for the new allocation to fit into young generation. Or that did not happen and some objects will be promoted to the old generation. If they can't be promoted, a full GC might be triggered - and if that does not free enough space an OutOfMemory might be thrown.

Hearen
  • 6,019
  • 2
  • 36
  • 50
Eugene
  • 102,901
  • 10
  • 149
  • 252
  • 2
    *"OutOfMemory is an error you can not recover from"* - That's a bit too broad of a statement. Some OOMEs are actually reasonably recoverable. – the8472 May 09 '17 at 10:54
  • 1
    @the8472 I actually never thought about it deep(or dealt with directly), so it is indeed too broad. Can you really recover from an OOM? Do you know any examples may be? – Eugene May 09 '17 at 11:02
  • 1
    @the8472 actually I think I found one that makes sense to me : http://stackoverflow.com/questions/2679330/catching-java-lang-outofmemoryerror/4745520#4745520. There could be cases when there is a need to allocate a *contiguous* chunk of memory also... – Eugene May 09 '17 at 11:09
2

In general, an OutOfMemoryError occurs when you have exceeded the maximum memory you have already allocated to the JVM. This amount can be changed when starting java using jvm parameters. e.g. -Xmx2G. Note that this amount isn't used immediately. See below.

GC (Allocation Failure) is similar, except it occurs when the garbage collector runs out of memory on the heap, and it attempts to allocate more. If your allocated memory is higher than your available system memory, this will fail. Essentially, the JVM tries to allocate memory which isn't there.

See for more information

killjoy
  • 1,782
  • 13
  • 12
  • If your allocated memory is higher than your available system memory, this will fail. Essentially, the JVM tries to allocate memory which isn't there. This sentence doesn't hold good. We have 32 GB ram , we are using 18GB for JVM. So as per your comments we should not get the Allocation Failure – user3024119 May 09 '17 at 07:32
  • [This answer](http://stackoverflow.com/a/28357523/2351110) may explain it better than I can. – killjoy May 09 '17 at 07:43