在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/網(wǎng)絡(luò)安全  HTML/ Node.js Promise resolve

Node.js Promise resolve

在使用await async的時(shí)候,定義一個(gè)async函數(shù):

async updateUserInfo(objectId, username, mobilePhoneNumber, appId){
    let replaceSql = `update xc_scm_leancloud_users set  username="${username}",mobilePhoneNumber="${mobilePhoneNumber}" where objectId="${objectId}" and appId="${appId}"`;
    scmSequelize.query(replaceSql);
}
調(diào)用:
updateUserInfo(objectId, username, mobilePhoneNumber, appId)
.catch(err => {
    logger.error('leancloudUser afterUpdate err: ', err);
    res.send(new XCResult(false, new XCError('', XC_BIZ_ERROR_TYPE.BIZ_ERROR,err)));
    return next();
});
在updateUserInfo()中沒有返回值的時(shí)候,整個(gè)服務(wù)器的內(nèi)存占用為90M左右,在updateUserInfo()中加上返回值:
 async updateUserInfo(objectId, username, mobilePhoneNumber, appId){
    let replaceSql = `update xc_scm_leancloud_users set  username="${username}",mobilePhoneNumber="${mobilePhoneNumber}" where objectId="${objectId}" and appId="${appId}"`;
    return scmSequelize.query(replaceSql);
}

服務(wù)器的內(nèi)存占用為140M+,這是怎樣產(chǎn)生的?我想問一下promise的resolve和reject對內(nèi)存的影響是什么?怎樣影響的?

回答
編輯回答
孤慣

關(guān)鍵要看你返回到哪里去了,是丟掉了還是存起來了。沒有返回查出結(jié)果直接就丟掉了,如果返回并保存起來了,內(nèi)存占用當(dāng)然要大一些。

2018年3月21日 05:31
編輯回答
念初

感覺是你異步函數(shù)里面的占用
promise用棧維護(hù)的,只要不是鏈的太長,或太多,promise不太會有影響的

2017年8月11日 16:36
編輯回答
任她鬧

我的理解是,雖然 scmSequelize.query是什么并不清楚,但肯定是一個(gè)function,return一個(gè)scmSequelize對象的方法里面可能包含了很多諸如this.xx之類的引用,當(dāng)執(zhí)行updateUserInfo這個(gè)異步方法時(shí),就形成了閉包(在callback的作用域使用scmSequelize作用域下的屬性)以致于引用沒有釋放。但是并沒有辦法解釋你加了return就突然一直多了50M這件事情。

2017年9月21日 16:35