check for out_of_memory() less often and only after allocating something.