开发者

dangling pointers java using arrays [duplicate]

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜