V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
LinJunzhu
V2EX  ›  Node.js

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

  •  
  •   LinJunzhu · 2019-07-26 22:22:06 +08:00 · 4225 次点击
    这是一个创建于 1728 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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  
       2019-07-27 10:45:41 +08:00 via iPhone
    你这个 get 是异步的吧,如果是同步的话这个变量也回被回收啊,但是这个 get 已经在执行了啊,
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1008 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 19:30 · PVG 03:30 · LAX 12:30 · JFK 15:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.