pub struct AutoreleasePool { /* private fields */ }
Expand description

An Objective-C autorelease pool.

The pool is drained when dropped.

This is not Send, since objc_autoreleasePoolPop must be called on the same thread.

And this is not Sync, since you can only autorelease a reference to a pool on the current thread.

Implementations

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.

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

Formats the value using the given formatter. Read more

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!

Formats the value using the given formatter.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.