mechanism that prevents OutOfMemory exception before it happened java

47 Views Asked by At

How can we predict or check if an OutOfMemory error will happen before creating a new instance? This mechanism must tell me that if I were to create one more object then an OutOfMemory error will occur.

what mechanism used for OutOfMemory handling.

Any solutions for this issue?

1

There are 1 best solutions below

0
Pierre Sevrain On

I guess it's very difficult (impossible?) to predict the memory state of the moment you decide to actually create the new object (other objects created, GC triggered, ...) Even a "test creation" is not reliable as it modify this state.

I'm really curious if someone has a clear solution on that.

I think I would go wrapping the object creation and managing the Exception the best I can.