add memory restraint checking