Struct objc2::rc::AutoreleasePool
source · pub struct AutoreleasePool { /* private fields */ }
Expand description
Implementations§
source§impl AutoreleasePool
impl AutoreleasePool
sourcepub unsafe fn ptr_as_ref<'p, T: ?Sized>(&'p self, ptr: *const T) -> &'p T
pub unsafe fn ptr_as_ref<'p, T: ?Sized>(&'p self, ptr: *const T) -> &'p T
Returns a shared reference to the given autoreleased pointer object.
This is the preferred way to make references from autoreleased objects, since it binds the lifetime of the reference to the pool, and does some extra checks when debug assertions are enabled.
For the mutable counterpart see ptr_as_mut
.
Safety
This is equivalent to &*ptr
, and shares the unsafety of that, except
the lifetime is bound to the pool instead of being unbounded.
sourcepub unsafe fn ptr_as_mut<'p, T: ?Sized>(&'p self, ptr: *mut T) -> &'p mut T
pub unsafe fn ptr_as_mut<'p, T: ?Sized>(&'p self, ptr: *mut T) -> &'p mut T
Returns a unique reference to the given autoreleased pointer object.
This is the preferred way to make mutable references from autoreleased objects, since it binds the lifetime of the reference to the pool, and does some extra checks when debug assertions are enabled.
For the shared counterpart see ptr_as_ref
.
Safety
This is equivalent to &mut *ptr
, and shares the unsafety of that,
except the lifetime is bound to the pool instead of being unbounded.
Trait Implementations§
source§impl Debug for AutoreleasePool
impl Debug for AutoreleasePool
source§impl Drop for AutoreleasePool
impl Drop for AutoreleasePool
source§fn drop(&mut self)
fn drop(&mut self)
Drains the autoreleasepool.
The clang documentation says that @autoreleasepool
blocks are not
drained when exceptions occur because:
Not draining the pool during an unwind is apparently required by the Objective-C exceptions implementation.
However, we would like to do this anyway whenever possible, since the unwind is probably caused by Rust, and forgetting to pop the pool will likely leak memory.
Fortunately, the above statement was true in the past, but since
revision 371
of objc4 (ships with MacOS 10.5) the exception is now
retained when @throw
is encountered.
Hence it is safe to drain the pool when unwinding.
TODO: Verify this claim on 32bit!