Back ported memory check function from 1.1 branch