Content deleted Content added
→Garbage collection: Replace links to C++'s std::shared_ptr and std::weak_ptr smart pointers (one subsection in the same article) with one link. Mark dubious statement. |
m Dating maintenance tags: {{Citation needed}} |
||
Line 11:
A very common case of such strong vs. weak reference distinctions is in tree structures, such as the [[Document Object Model]] (DOM), where parent-to-child references are strong, but child-to-parent references are weak. For example, Apple's [[Cocoa (API)|Cocoa]] framework recommends this approach.<ref>{{cite web|url=https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmPractical.html|title=Practical Memory Management|website=developer.apple.com}}</ref> Indeed, even when the object graph is not a tree, a tree structure can often be imposed by the notion of object ownership, where ownership relationships are strong and form a tree, and non-ownership relationships are weak and not needed to form the tree – this approach is common in [[C++]] (pre-C++11), using raw pointers as weak references. This approach, however, has the downside of not allowing the ability to detect when a parent branch has been removed and deleted. Since the [[C++11]] standard, a solution was added by using [[Smart_pointer#shared_ptr_and_weak_ptr|shared_ptr and weak_ptr]], inherited from the [[Boost (C++ libraries)|Boost]] library.
Weak references are also used to minimize the number of unnecessary objects in memory by allowing the program to indicate which objects are of minor importance by only weakly referencing them.{{citation needed|date=February 2023}}
== Variations ==
|