如何销毁Ruby对象? [英] How to destroy Ruby object?

查看:69
本文介绍了如何销毁Ruby对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设有一个简单的对象,例如:

Suppose there is simple object like:

object = Object.new

据我所知,这会在内存 (RAM) 中创建对象.

As I know this creates Object in memory (RAM).

有没有办法从内存中删除这个对象?

Is there a way to delete this object from RAM?

推荐答案

除了破解底层 C 代码,没有.垃圾收集由运行时管理,因此您不必担心.这是一个不错的参考 关于 Ruby 2.0 中的算法.

Other than hacking the underlying C code, no. Garbage collection is managed by the runtime so you don't have to worry about it. Here is a decent reference on the algorithm in Ruby 2.0.

一旦您不再引用内存中的对象,垃圾收集器就会开始工作.你应该没事.

Once you have no more references to the object in memory, the garbage collector will go to work. You should be fine.

这篇关于如何销毁Ruby对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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