设为首页 - 加入收藏
广告 1000x90
您的当前位置:当前位置: 首页 >

正文

J***aScript的闭包会无法被垃圾回收吗?

来源: 编辑: 时间:2025-06-25 03:45:15

你理解反了吧,正因为无法引用到它,所以才会被垃圾回收。

垃圾回收靠的就是从根节点开始遍历所有对象,遍历不到的就是垃圾。

先来演示一个能正常引用的: function outer() { let str = "string"; function inner() { console.log(str); } return inner; } window.foo = outer(); outer 返回的 inner 函数由于被全局变量 foo 所引用,所以相关的一系类对象都不会被垃圾回收。

在 DevTools 内存分析面板可以看到,存在一个 contex…。

J***aScript的闭包会无法被垃圾回收吗?
    {dede:pagebreak/}

相关文章:

    {dede:likearticle row='10' channelid='1' typeid="all"}
  • [/]
  • {/dede:likearticle}

相关推荐:

  • [/]
  • [/]
  • [/]
  • [/]
  • [/]
  • [/]
  • [/]
  • [/]
  • [/]
  • [/]

网友评论:

{dede:include file='ajaxfeedback.htm' /}

模板天下 www.mobantianxia.com 联系QQ:498872301 邮箱:498872301@qq.com

版权@|备案:闽-ICP备90270407号-1|网站地图

Top