ohadravid / wmi-rs

WMI crate for rust
Apache License 2.0
80 stars 27 forks source link

Dropped IWbemClassWrapper scenario #99

Open theKidOfArcrania opened 3 weeks ago

theKidOfArcrania commented 3 weeks ago

The comments for IWbemClassWrapper mentions something about it taking care of releasing the object when dropped. Can you elaborate on this if this is true? I don't see anywhere where this suggest that this code releases any resources when this object is dropped.

Specific comments:

/// A wrapper around a raw pointer to IWbemClassObject, which also takes care of releasing
/// the object when dropped.
ohadravid commented 3 weeks ago

Hi @theKidOfArcrania ,

It's a good question: It used be clearer in perv. versions of this struct.

Currently, IWbemClassWrapper is a wrapper around windows::Win32::System::Wmi::IWbemClassObject, which is defined like this:

#[repr(transparent)]
#[derive(...)]
pub struct IWbemClassObject(::windows_core::IUnknown);

And IUnknown, as documented here, has a drop impl which calls Release:

impl Drop for IUnknown {
    fn drop(&mut self) {
        unsafe {
            (self.vtable().Release)(std::mem::transmute_copy(self));
        }
    }
}

So at least AFIK, everything should be released as expected.