You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit be61879
Browse filesBrowse the repository at this point in the historyBrowse files
You can find more documentation about Objective-C interop using FFIgen in
19
+
the TOPICS section in [FFIgen's API documentation](https://pub.dev/documentation/ffigen/latest/).
20
+
18
21
## Memory management
19
22
20
23
Objective C and Dart use different styles of memory management. Dart is garbage
@@ -36,3 +39,6 @@ reference counting issue, it may occasionally be necessary to manually control
36
39
the ref count. The ref count of the Objective C object can be controlled from
37
40
Dart by the `retain` and `release` options in the Dart wrapper object
38
41
constructors, and by the `retainAndReturnPointer()` and `release()` methods.
42
+
43
+
For more details on avoiding reference cycles and leaks, see the
/// here (the [Future] it returns will not be awaited). Objective-C autorelease
37
37
/// pools form a strict stack, and allowing async execution gaps inside the pool
38
38
/// scope could easily break this nesting, so async functions are not supported.
39
+
///
40
+
/// See the [Objective-C Memory Management guide](https://pub.dev/documentation/ffigen/latest/topics/Objective-C%20Memory%20Management-topic.html).
Copy file name to clipboardExpand all lines: pkgs/objective_c/lib/src/internal.dart
+37Lines changed: 37 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -287,8 +287,20 @@ abstract final class _ObjCReference<T extends NativeType>
287
287
_isReleased.value =true;
288
288
}
289
289
290
+
/// Manually releases the underlying reference.
291
+
///
292
+
/// Throws a [DoubleReleaseError] if this reference has already been
293
+
/// released.
294
+
///
295
+
/// See the [Objective-C Memory Management guide](https://pub.dev/documentation/ffigen/latest/topics/Objective-C%20Memory%20Management-topic.html).
290
296
voidrelease() =>_release(r.objectRelease);
291
297
298
+
/// Releases the reference by adding it to the current autorelease pool.
299
+
///
300
+
/// Throws a [DoubleReleaseError] if this reference has already been
301
+
/// released.
302
+
///
303
+
/// See the [Objective-C Memory Management guide](https://pub.dev/documentation/ffigen/latest/topics/Objective-C%20Memory%20Management-topic.html).
292
304
Pointer<T> autorelease() {
293
305
_release(r.objectAutorelease);
294
306
return _finalizable.ptr;
@@ -301,6 +313,10 @@ abstract final class _ObjCReference<T extends NativeType>
301
313
@override
302
314
intget hashCode => _finalizable.ptr.hashCode;
303
315
316
+
/// The raw pointer to the underlying Objective-C object or block.
317
+
///
318
+
/// Throws a [UseAfterReleaseError] if this reference has already been
319
+
/// released.
304
320
Pointer<T> get pointer {
305
321
if (isReleased) {
306
322
throwUseAfterReleaseError();
@@ -309,12 +325,22 @@ abstract final class _ObjCReference<T extends NativeType>
309
325
return _finalizable.ptr;
310
326
}
311
327
328
+
/// Retains the underlying reference and returns the raw pointer.
329
+
///
330
+
/// The caller takes ownership of the retained reference (+1 retain count)
331
+
/// and is responsible for manually releasing it.
332
+
///
333
+
/// See the [Objective-C Memory Management guide](https://pub.dev/documentation/ffigen/latest/topics/Objective-C%20Memory%20Management-topic.html).
312
334
Pointer<T> retainAndReturnPointer() {
313
335
final ptr = pointer;
314
336
_retain(ptr);
315
337
return ptr;
316
338
}
317
339
340
+
/// Retains the underlying reference and adds it to the current autorelease
341
+
/// pool, returning the raw pointer.
342
+
///
343
+
/// See the [Objective-C Memory Management guide](https://pub.dev/documentation/ffigen/latest/topics/Objective-C%20Memory%20Management-topic.html).
@@ -354,6 +384,9 @@ final class ObjCObjectRef extends _ObjCReference<r.ObjCObjectImpl> {
354
384
}
355
385
356
386
/// Base class for all Objective-C objects.
387
+
///
388
+
/// For details on Objective-C runtime types and subtyping with Dart extension
389
+
/// types, see the [Objective-C Runtime Types guide](https://pub.dev/documentation/ffigen/latest/topics/Objective-C%20Runtime%20Types-topic.html).
0 commit comments