开发者

dangling pointers java using arrays [duplicate]

开发者 https://www.devze.com 2023-02-15 22:38 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Creating a dangling pointer using Java
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Creating a dangling pointer using Java

how to create dangling pointers in java but this time using arrays as memor开发者_JAVA百科y allocators?


There can't be dangling pointers in Java. The language is defined in a way that makes it impossible.

Object will only ever be removed by garbage collection when they are no longer reachable.

The closest you can get to a dangling pointer is a reference that holds null (i.e. doesn't point to any object). But that's still a defined value with defined behaviour.


Since Java uses a garbage collector, it's impossible to create a dangling pointer in Java. I guess if you misinterpret what a "dangling pointer" is, you could see the null pointers a newly created array (of a reference type) is filled with as "dangling pointers".


You cannot create a dangling pointer or reference in Java Creating a dangling pointer using Java

0

精彩评论

暂无评论...
验证码 换一张
取 消