Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic memory management of blocks #573

Open
madsmtm opened this issue Feb 2, 2024 · 0 comments
Open

Automatic memory management of blocks #573

madsmtm opened this issue Feb 2, 2024 · 0 comments
Labels
A-block2 Affects the `block2` crate A-objc2 Affects the `objc2`, `objc-sys` and/or `objc2-encode` crates enhancement New feature or request

Comments

@madsmtm
Copy link
Owner

madsmtm commented Feb 2, 2024

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?

@madsmtm madsmtm added enhancement New feature or request A-objc2 Affects the `objc2`, `objc-sys` and/or `objc2-encode` crates A-block2 Affects the `block2` crate labels Feb 2, 2024
@madsmtm madsmtm mentioned this issue Feb 2, 2024
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-block2 Affects the `block2` crate A-objc2 Affects the `objc2`, `objc-sys` and/or `objc2-encode` crates enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant