NobodyIsMe
V2EX  ›  Node.js

请教下 NodeJs 关于回调函数的内存回收策略

  •  
  •   NobodyIsMe · Jul 26, 2019 · 4711 views
    This topic created in 2521 days ago, the information mentioned may be changed or developed.
    const request = require('request')
    
    let hello = function() {
        
        let result = request.get("http://baidu.com", function(error, response){
        	console.log(response)
        }
        
    }
    
    
    hello()
    
    

    hello() 函数执行完毕后, 假设此时的 request 请求还未返回,一直卡住,

    问题:

    1、一段时间后进行 GC,会回收掉 result 这个变量吗? 2、hello 函数内的所有数据都会被回收掉吗? 若被回收掉了,request 的 callback 是否没机会执行了?

    ookkxw
        1
    ookkxw  
       Jul 27, 2019 via iPhone
    你这个 get 是异步的吧,如果是同步的话这个变量也回被回收啊,但是这个 get 已经在执行了啊,
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2813 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 13:25 · PVG 21:25 · LAX 06:25 · JFK 09:25
    ♥ Do have faith in what you're doing.