Add global heap out-of-memory detection. Helps deal with #176.