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> {
64
64
/// - Returns: An unmanaged reference to the object passed as `value`.
65
65
@_transparent
66
66
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)
68
70
}
69
71
70
72
/// Creates an unmanaged reference without performing an unbalanced
@@ -219,6 +221,11 @@ public struct Unmanaged<Instance: AnyObject> {
219
221
}
220
222
221
223
/// 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.
222
229
@_transparent
223
230
public func retain( ) -> Unmanaged {
224
231
Builtin . retain ( _value)
You can’t perform that action at this time.
0 commit comments