Skip to content

Fix leak in manganis iOS FFI wrappers: hold Retained<AnyObject> instead of a raw pointer - #5733

Merged
jkelleyrtp merged 1 commit into
mainfrom
devin/1785804701-ffi-ios-release
Aug 4, 2026
Merged

Fix leak in manganis iOS FFI wrappers: hold Retained<AnyObject> instead of a raw pointer#5733
jkelleyrtp merged 1 commit into
mainfrom
devin/1785804701-ffi-ios-release

Conversation

@nicoburns

Copy link
Copy Markdown
Member

Summary

Fixes #5722.

The iOS/macOS wrappers generated by #[manganis::ffi] constructed their Objective-C instance with alloc + init (+1 retain) and stored it as a bare *mut AnyObject, so dropping the Rust value never sent release — every Bridge::new() leaked its object (and any system resource it owned, e.g. a CLLocationManager). The Android arm already had correct ownership via jni::objects::GlobalRef.

The generated type now holds objc2::rc::Retained<AnyObject>, which takes over the +1 reference and releases on drop:

pub struct #name { inner: Retained<AnyObject> }

// new():
let instance: *mut AnyObject = msg_send![class, alloc];
let instance: *mut AnyObject = msg_send![instance, init];
let inner = Retained::from_raw(instance).ok_or("Failed to initialize instance")?; // replaces the null check

// method calls on a receiver:
msg_send![Retained::as_ptr(&this.inner) as *mut AnyObject, selector...]

from_raw(ptr) likewise wraps the pointer in Retained::from_raw and is documented as taking ownership of a +1 reference (it now panics on null).

Verified the generated code shape type-checks against objc2 0.6.4 on aarch64-apple-darwin (full cross-check of the macro output isn't possible on Linux CI hosts since objc2-exception-helper needs an ObjC compiler).

Link to Devin session: https://dioxus.staging.devinenterprise.com/sessions/cd9de105cf904808b16b468c829b5ac1
Requested by: @nicoburns

@nicoburns nicoburns self-assigned this Aug 4, 2026
@staging-devin-ai-integration

Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@jkelleyrtp
jkelleyrtp merged commit 385f6ba into main Aug 4, 2026
23 checks passed
@jkelleyrtp
jkelleyrtp deleted the devin/1785804701-ffi-ios-release branch August 4, 2026 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

manganis: generated iOS FFI wrapper never releases the Objective-C instance

2 participants