Closed VisualEhrmanntraut closed 2 months ago
If you take a look at the -[NSMenuItem target]
property, you will see that it says "weak". This means that when you call file_open.setTarget
and file_save.setTarget
, the menu items don't prevent the target
value from being destroyed and deallocated when it goes out of scope.
The reason this worked in objc
was likely due to a memory leak somewhere in your application, objc2
avoids those, but in turn you must handle stuff like this correctly.
If there is a natural place that you can store the target at the end of the scope, I'd recommend you do that, otherwise it's probably fine to leak it manually using std::mem::forget(target)
.
the documentation here is sparse
There's a bit more documentation on menus in here, but yeah, it definitely is limited.
Interesting how it can tell that it got deallocated instead of crashing. Calling forget on it seems to work, thanks.
It's kinda like target
is an std::sync::Arc<PlistOxideMenu>
, and NSMenuItem
stores a std::sync::Weak
to that, though indeed this is something that we don't often use in the Rust world.
Hello. I am migrating my project to use objc2 from objc, and I am encountering an issue. I am building a menu bar on top of an egui/winit app, and after switching to objc2, the menu bar options are greyed out. This suggests that the internal check for whether the action exists failed. I'm not sure if there's a problem with the crate or if it's my oversight (the documentation here is sparse, and my understanding of obj-c isn't that great). Here's the relevant parts of the code