GLIB Rust bindings and glib::Object::new() and a big memory leak, perhaps

I have a Rust GTK program and am creating my own ListModel.
The list model item() method is

fn item(&self, position: u32) -> Option<Object> {
            match get_earth_model().airports
                .read()
                .expect("Unable to get a lock on the airports")
                .iter().nth(position as usize) {
                Some(airport) => {
                    let ao = AirportObject::new(airport);
                    Some(Object::from(ao))
                }

                None => None
            }
        }

and my AirportObject::new(airport) method is

    pub fn new(airport: &Arc<Airport>) -> AirportObject {
        let obj: AirportObject = glib::Object::new();
        obj.downcast_ref::<AirportObject>()
            .expect("The item has to be an <AirportObject>.")
            .imp().set_airport(airport.clone());
        obj
    }

Tracing the code while trying to implement some other stuff, I see this is called repeatedly and now I assume the call to glib::Object::new(), while valid safe Rust code, is actually a big fat memory leak, but I’m not sure. I’m not holding a reference to the GObject or freeing it anywhere. Should I?

In a nutshell, if I call glib::Object::new(), do I need to somewhere and somehow cleanup that object?

No, it’s behaving like an Arc. You’re likely keeping a reference around somewhere or introduce a reference cycle between that object and something else (e.g. the Arc<Airport>?).

Thanks @sdroege. Nice to know.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.