Fix bugs in dealing with low-memory situations when the system has run out