Handling ``Out of Memory'' Errors

Abstract

An ``out of memory'' error can be catastrophic for a program,
especially one written in a language such as Java that uses memory
allocation frequently. Handling such an error can easily lead to its
re-occurrence. A handler will often need memory while it is freeing
resources (by persisting data to secondary storage, or clearing
caches). A simple technique involves pre-allocating a large chunk of
memory that is then freed at the start of the handler. I report some
experience using this technique and discuss some of the problems that
arise when reasoning about the behavior of memory error handlers.