简体   繁体   English

从JRuby销毁Java类的对象

[英]Destroying objects of Java classes from JRuby

We can create objects of Java classes from JRuby using .new method. 我们可以使用.new方法从JRuby创建Java类的对象。 But is there any way to manually destroy/deallocate/call destructor of that object in JRuby? 但是,有什么方法可以在JRuby中手动销毁/释放/调用该对象的析构函数?

Given that JRuby runs inside a JVM, there is no way of saying "free an object". 鉴于JRuby在JVM中运行,因此无法说“释放对象”。 Even Ruby does not have a notion explicit "free" operator. 甚至Ruby也没有明确的“免费”运算符概念。 That is managed by the VM. 这是由VM管理的。

What is it that you are trying to achieve? 您要达到的目标是什么?

A big (advertised at least) advantage of using a language that runs in a managed environment (like a VM) is so that, well, its managed. 使用在托管环境(如VM)中运行的语言的一大优势(至少是广告上说的)是可以对其进行托管的。 Dealing with garbage is one of them. 处理垃圾就是其中之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM