File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -64,7 +64,9 @@ public struct Unmanaged<Instance: AnyObject> {
6464 /// - Returns: An unmanaged reference to the object passed as `value`.
6565 @_transparent
6666 public static func passRetained( _ value: Instance ) -> Unmanaged {
67- return Unmanaged ( _private: value) . retain ( )
67+ // Retain 'value' before it becomes unmanaged. This may be its last use.
68+ Builtin . retain ( value)
69+ return Unmanaged ( _private: value)
6870 }
6971
7072 /// Creates an unmanaged reference without performing an unbalanced
@@ -219,6 +221,11 @@ public struct Unmanaged<Instance: AnyObject> {
219221 }
220222
221223 /// Performs an unbalanced retain of the object.
224+ ///
225+ /// Note: Use Umanaged.passRetained(object) instead to ensure that
226+ /// the reference to object is retained before it becomes
227+ /// unmanaged. Once a reference is unmanaged, its underlying object
228+ /// may be freed by the system.
222229 @_transparent
223230 public func retain( ) -> Unmanaged {
224231 Builtin . retain ( _value)
You can’t perform that action at this time.
0 commit comments