What is the difference between garbage links and hanging out?

What is the difference between garbage links and dangling links?

+4
source share
3 answers

A dangling link is a reference to an object that no longer exists. Garbage is an object that cannot be reached by reference.

Dangling links do not exist in garbage collections, because objects only return when they are no longer available (only garbage is collected). In some languages ​​or frameworks, you can use "weak links" that can be left dangling, as they are not taken into account during the collection.

In languages ​​with manual memory management, such as C or C ++, you may encounter dangling pointers by doing this, for example:

int * p = new int; delete p; int i = *p; // error, p has been deleted! 
+17
source

A spoofed link is a reference to an object that no longer exists.

What is considered garbage depends on the implementation of your garbage collector.

Using both trace and reference counting GCs, dangling links cannot exist (unless there is a GC implementation error), since only these elements are considered suitable for garbage collection to which there is no link.

Thus, dangling links are a problem almost exclusively for systems with manual memory management.

+3
source

Dangling Reference: a reference to a memory address that was originally allocated but is now freed

 int x= 1000; //creates a new memory block int* p = x; // *p is the pointer to address block 1000(mem location) int *p = 20; printf("%d",*p); //This pointer prints 20 delete p; printf("%d",*p); // This would throw an error, because now p is // inaccessible or dangling. *p is a dangling pointer. 

Garbage: memory that was allocated on the heap and was not explicitly freed, but not accessible to the program. Java has a garbage collector. It removes dangling pointers and other garbage memory in a timely manner.

0
source

All Articles