rust_macios/foundation/ns_autoreleasepool.rs
1use objc::{msg_send, sel, sel_impl};
2
3use crate::{object, objective_c_runtime::{
4 id,
5 macros::{interface_impl},
6 traits::PNSObject,
7}};
8
9object! {
10 /// An object that supports Cocoa’s reference-counted memory management system.
11 unsafe pub struct NSAutoreleasePool;
12}
13
14#[interface_impl(NSObject)]
15impl NSAutoreleasePool {
16 /* Managing a Pool
17 */
18
19 /// In a reference-counted environment, releases and pops the receiver; in
20 /// a garbage-collected environment, triggers garbage collection if the
21 /// memory allocated since the last collection is greater than the current
22 /// threshold.
23 #[method]
24 pub fn drain(&mut self) {
25 unsafe { msg_send![self.m_self(), drain] }
26 }
27
28 /// Adds a given object to the active autorelease pool in the current thread.
29 ///
30 /// # Arguments
31 ///
32 /// * `object` - The object to be added to the pool in the current thread.
33 #[method]
34 pub fn add_object(&mut self, object: id) {
35 unsafe { msg_send![self.m_self(), addObject: object] }
36 }
37}
38
39impl Default for NSAutoreleasePool {
40 fn default() -> Self {
41 Self::m_new()
42 }
43}