标题说明了一切。也许有一种方法可以像这样调用def destruct; delete self;end
?
问问题
287 次
1 回答
5
这是可能的,但绝对不推荐,我将向您展示的方式将来可能会改变或中断。你为什么需要这个?GC 的想法正是不用担心这些事情。
class Foo
def initialize
@x = 10
end
def finalize
puts "Never called"
end
end
foo = Foo.new
p foo # => #<Foo:0x10be27fd0 @x=10>
GC.free(Pointer(Void).new(foo.object_id)) # This line frees the memory
p foo # => #<Foo:0x10be27fd0 @x=1>
于 2016-02-08T14:37:06.953 回答