关闭内存泄漏 [英] Closure memory leaks

查看:135
本文介绍了关闭内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对垃圾收集语言中的内存泄漏(不需要的引用)的可能性感兴趣

I'm interested in the possibility in memory(unneeded reference) leaks of memory leaks in garbage collected languages

由存储的闭包中捕获的变量引起的
(可能作为对象系统的一部分,或作为基于稍后要评估的输入的构建动作的一部分)。

caused by variables caught in closures which are stored (perhaps as part of an object system or as part of building actions based on input to be evaluated later).

有这样的事情的任何语言有点常见?

Are there any languages where this sort of thing is somewhat common? If so what are the patterns to watch out for in those languages to prevent it?

推荐答案

只要关闭被引用,捕获的变量将被保留。因此,您需要注意在哪里创建对这些闭包的引用。

As long as the closure is referenced, the captured variables will be kept. As a result, you need to be careful about where you create references to those closures.

未取消订阅的事件处理程序是许多类型的泄漏的潜在来源。然而,我真的不能想到任何通用模式,将帮助你在每一种可能的方式,你可能使用闭包:)

Event handlers that are not unsubscribed are a potential source of many types of leaks. However, I can't really think of any generic patterns that will help you in every conceivable way you may be using closures :)

这篇关于关闭内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆