You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am a little confused with a Rust implementation of autoreleasepool... When I type a something as below:
fn func(mtm: MainThreadMaker) -> Id<NSSomeObject> {
autoreleasepool(|_| {
let alloc_1 = mtm.alloc();
let some_object: Id<NSSomeObject> = NSSomeObject::alloc(alloc_1);
let alloc_2 = mtm.alloc();
let child_object: Id<NSChildObject> = NSChildObject::alloc(alloc_2);
some_object.set_child(&child_object); // Replaced an old automatically-created child on Obj C side.
some_object
})
}
What will happen? Does autoreleasepool release the old automatically-created child on Obj C side? Or will it delete child_object too?
P.S. Sorry for the noobie's question, I am not a Objective C programmer, the autoreleasepool is like a black box for me.
The text was updated successfully, but these errors were encountered:
fn set_icon(&self, icon: Option<&Icon>) {
autoreleasepool(|_| {
let mtm = MainThreadMarker::from(self);
let app = NSApp(mtm);
match icon {
Some(icon) => {
let ns_image = icon.get_impl().get_native();
unsafe { app.setApplicationIconImage(Some(&ns_image)) };
}
None => unsafe { app.setApplicationIconImage(None) },
}
});
}
Should I use the autoreleasepool in such cases? There can be an old application icon image as I get.
madsmtm
added
question
Further information is requested
A-objc2
Affects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` crates
labels
May 28, 2024
I think that by understanding autorelease pools in Objective-C (builtin @autoreleasepool), you'd get a lot of the way there to understanding it in Rust. There's a link to some docs here, I've added a link to that in 2066b7f.
In short, you use it mostly to reduce the peak memory footprint, it shouldn't affect safety or soundness in any way.
Specifically for setApplicationIconImage, the answer is that it's implementation-defined whether it releases the previous image into the autorelease pool or not (in reality, it's unlikely that it will, but it might have done so in the past, or might do so in the future).
Hello!
I am a little confused with a Rust implementation of
autoreleasepool
... When I type a something as below:What will happen? Does
autoreleasepool
release the old automatically-created child on Obj C side? Or will it deletechild_object
too?P.S. Sorry for the noobie's question, I am not a Objective C programmer, the
autoreleasepool
is like a black box for me.The text was updated successfully, but these errors were encountered: