垃圾收集器如何在Java中用于原始数据类型? [英] How does Garbage Collector works for Primitive Data type in Java?

查看:84
本文介绍了垃圾收集器如何在Java中用于原始数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如我们通过引用计数和其他这样的算法所了解的,Object的工作原理。
但是对于Primitive Data类型,我们不能使它成为 NULL like:

  int a = NULL; 

垃圾收集器如何在Java中用于Primitive数据类型?


As we know for Object its works through Reference counting and other such Algorithm.
But for Primitive Data types, we can't make it NULL like:

int a = NULL;

How does Garbage Collector work for Primitive datatypes in Java?

解决方案

Primitive data types are either fields in objects or used in arrays which themselves are objects. For the garbage collector these fields are not relevant, because they do not contain pointers. They can be perfectly ignored and will be freed together with the object/array once it gets garbage collected.

这篇关于垃圾收集器如何在Java中用于原始数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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