3 ms·
> Memory allocation errors are special in all languages. Actually no, not in Java! You can catch java.lang.OutOfMemoryError just like any other exception. If t
by grishka 4y ago
> Memory allocation errors are special in all languages.
Actually no, not in Java! You can catch java.lang.OutOfMemoryError just like any other exception. If the memory pressure is high though, it's possible that another OOM would be thrown from the code that handles it.
- knorker 4y agoYou can catch std::bad_alloc in C++, too. That's not my point. Especially because destructors free immediately (not wait for GC) I would expect C++ to handle this as a language much better than Java. But when memory pressure is high you can get killed at any time. E.g. on Linux the OOM killer might decide that it's best for the system that your process dies, even if you've not done memory allocations or needed to page fault for hours. IIRC OpenBSD doesn't overcommit memory, but in my experience its system stability is much worse when memory is low.