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
• Improper release of Objective-C object in Rust-to-ObjC conversion
• Retain cycle between Rust and Objective-C objects
• Exception thrown during object initialization, bypassing normal cleanup
• Autorelease pool not properly set up or drained
• Incorrect implementation of Drop trait for Rust wrapper
• Memory management mismatch between Rust's ownership model and ObjC's reference counting
• Unhandled edge case in exception handling code
• Thread-safety issue causing object to be retained on another thread
• Incorrect use of unsafe code in FFI layer
• Hidden retain in Apple's SCStreamConfiguration implementation
things i tried to fix
using autoreleasepool
impl my own autoreleasepool
using verify message
drop manually
impl drop for unsafestreamconf
print stuff everywhere
count retain
use panic unwind rust feat
commenting out properties (still leak on the init msg_send)
other stuff
anything else i should try?
how to reproduce
add this to examples/leak.rs
use std::process::Command;use screencapturekit::{
cm_sample_buffer::CMSampleBuffer,
sc_content_filter::{InitParams,SCContentFilter},
sc_error_handler::StreamErrorHandler,
sc_output_handler::{SCStreamOutputType,StreamOutput},
sc_shareable_content::SCShareableContent,
sc_stream::SCStream,
sc_stream_configuration::{PixelFormat,SCStreamConfiguration},
sc_types::base::CMTime,};use screencapturekit_sys::{
content_filter::{UnsafeContentFilter,UnsafeInitParams},
shareable_content::UnsafeSCShareableContent,};pubstructCapturer{}implCapturer{pubfnnew() -> Self{println!("Capturer initialized");Capturer{}}}implStreamErrorHandlerforCapturer{fnon_error(&self){eprintln!("ERROR!");}}implStreamOutputforCapturer{fndid_output_sample_buffer(&self,_sample:CMSampleBuffer,_of_type:SCStreamOutputType){println!("New frame recvd");}}fnmain(){println!("Starting");for _ in0..1{// Repeat the process multiple times to amplify leaks// Create SCShareableContent and SCContentFilterlet display = SCShareableContent::current().displays.pop().unwrap();let windows = SCShareableContent::current().windows;// Create multiple filterslet _filter1 = SCContentFilter::new(InitParams::DisplayExcludingWindows(
display.clone(),
windows,));let _filter2 = SCContentFilter::new(InitParams::Display(display.clone()));let _filter3 =
SCContentFilter::new(InitParams::DisplayExcludingWindows(display.clone(),vec![]));// Create multiple configurationslet _config1 = SCStreamConfiguration{width:1920,height:1080,
..Default::default()};let _config2 = SCStreamConfiguration{width:1280,height:720,
..Default::default()};// Create and immediately drop streamslet init_params = InitParams::Display(display);let filter = SCContentFilter::new(init_params);letmut sc_stream = SCStream::new(filter, _config1,Capturer{});let output = Capturer{};
sc_stream.add_output(output,SCStreamOutputType::Screen);// Force drop of sc_streamdrop(sc_stream);}// Get the current process IDlet pid = std::process::id();// Run the 'leaks' commandlet output = Command::new("leaks").args(&[pid.to_string()]).output().expect("Failed to execute leaks command");// Check the output for leakslet stdout = String::from_utf8_lossy(&output.stdout);let stderr = String::from_utf8_lossy(&output.stderr);println!("leaks stdout: {}", stdout);println!("leaks stderr: {}", stderr);}
RUST_BACKTRACE=1 MallocStackLogging=1 cargo run --example leak
But I would still recommend using something like cidre or just building the screencapturekit bindings for audio yourself.
But going forward, I'll update the readme for this crate to make it more clear that it is not production ready. And see where things are when I get time to complete the PR.
Looking at cidr, it's taking a much more systematic approach. And by using its building blocks it should be fairly simple to add any missing parts (audio capture).
hey i fixed a bunch of memory leaks in here
there is a last leak i'm facing:
theory of the problem
• Improper release of Objective-C object in Rust-to-ObjC conversion
• Retain cycle between Rust and Objective-C objects
• Exception thrown during object initialization, bypassing normal cleanup
• Autorelease pool not properly set up or drained
• Incorrect implementation of Drop trait for Rust wrapper
• Memory management mismatch between Rust's ownership model and ObjC's reference counting
• Unhandled edge case in exception handling code
• Thread-safety issue causing object to be retained on another thread
• Incorrect use of unsafe code in FFI layer
• Hidden retain in Apple's SCStreamConfiguration implementation
things i tried to fix
init
msg_send)anything else i should try?
how to reproduce
add this to
examples/leak.rs
thank you
related issue:
The text was updated successfully, but these errors were encountered: