How Garbage collector in V8 treats Promises when assigned to a new object(shallow copy)?

153 views Asked by At
let appLogin = null;
    SomeModel.findOne({
            where: {id: req.user.id},
            attributes: ["id","property_id"],
            raw: true,
        })
        .then((login) => {
            if(!login){
                throw new CustomErrors.InvalidToken("ER401");
            }             
            appLogin = login; return null;
        }
        .then((nullRecieved) => {
            console.log(appLogin)   
        })
        .catch((error) => {console.log(error)})

I'm facing a memory leak issue, and started debugging recently, resolved few things. But it seems I have to more concern about object references and garbage collections, in above code sample, SomeModel.findOne returns a promise, I'm assigning that promise to a new object(shallow copy) appLogin. Should I make the deep copy of that promise? Pretty confused about the promise references to new object, will garbage collector treat that promise as garbage after going to the next .then()? Thanks in advance. : )

0

There are 0 answers