取消引用未使用的对象是否会提高冗长方法的性能?

发布于 2024-09-30 13:33:14 字数 292 浏览 0 评论 0原文

可能的重复:
将 Java 对象设置为 null 还会有任何作用吗?

取消引用未使用的对象(分配 null)会提高冗长方法的性能吗?如果它增加,是否有任何经验法则来决定何时分配 null。因为这需要在代码中执行额外的步骤。

Possible Duplicate:
Does setting Java objects to null do anything anymore?

Will dereferncing the unused object(assigning with null) increase performance in lengthy methods? If it increase, is there is any thumb rule for deciding when to assign null. since this requires an extra step in the code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

执笔绘流年 2024-10-07 13:33:14

这取决于上下文。如果将 null 值分配给未使用的对象,那么它将有资格进行垃圾收集。但不能保证内存会释放。

It depends on the context. If you assign null value to an unused object then it will become eligible for garbage collected. But there is no guarantee that the memory will become free.

一抹苦笑 2024-10-07 13:33:14

粗略地说,不会,或者说不太可能。这就是我将采取的方法,

  1. 通过拆分长方法来引入新方法,并适当地命名它们
  2. 现在检查到底在哪里存在性能问题。您可以使用一些探查器,但即使记录每个方法的开始时间和结束时间也会提供一些想法
  3. 然后解决这个问题

Loosely speaking, it doesn't or say very unlikely. This is how I will approach,

  1. Introduce new methods by splitting the long method, and name those appropriately
  2. Now check where exactly you have performance problem. You can use some profiler, but even logging start time and end time for each method will provide some idea
  3. Then fix that
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文