madsmtm / objc2

Bindings to Apple's frameworks in Rust
https://docs.rs/objc2/
MIT License
280 stars 35 forks source link

Automatic memory management of blocks #573

Open madsmtm opened 3 months ago

madsmtm commented 3 months ago

It would be nice if we could get automatic memory management for blocks as well, instead of having to specify returned blocks as *mut Block<dyn Fn()>, and then converting those with RcBlock::copy.

If I'm reading the ARC spec right, it seems like blocks are actually autoreleased according to (mostly) the same rules as other Objective-C objects, and that we need to use objc_retainAutoreleasedReturnValue to access returned block pointers?

A few examples of more complex memory-management:

Also, should blocks be allowed in Id?