function checkMemory(context) {
//check memory usage
if (context.getRemainingUsage() <= 100){
var stateMain = nlapiYieldScript();
if( stateMain.status == 'FAILURE'){
nlapiLogExecution("debug","Failed to yield script (do-while), exiting: Reason = " + stateMain.reason + " / Size = " + stateMain.size);
throw "Failed to yield script";
} else if ( stateMain.status == 'RESUME' ){
nlapiLogExecution("debug", "Resuming script (do-while) because of " + stateMain.reason+ ". Size = " + stateMain.size);
}
}
}