问题描述
如何使用Java创建悬空指针?
How can i create a dangling pointer using Java?
推荐答案
根据 Wikipedias定义在下面, 否 .
According to Wikipedias definition below, no.
在不修改指针值的情况下删除或释放对象时会出现悬空指针,因此指针仍指向已释放内存的内存位置
Dangling pointers arise when an object is deleted or deallocated, without modifying the value of the pointer, so that the pointer still points to the memory location of the deallocated memory
没有办法删除(或垃圾收集")(如果您愿意的话)某些引用仍指向的对象.
There is no way to delete (or "garbage collect" if you so wish) an object which some reference still points to.
在上面的维基百科文章中,您确实可以阅读:
Further down in the above Wikipedia article you can indeed read:
使引用 not 指向(有效")对象的唯一方法是为其分配null.
The only way to make a reference not point to an ("valid") object, is to assign null to it.
这篇关于使用Java创建悬挂指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!