How can I check if an object was deleted?

Sebastian Dröge sebastian at centricular.com
Sun Apr 18 13:41:28 UTC 2021


On Sun, 2021-04-18 at 06:50 -0500, omer.tal wrote:
> 
> I'm implementing an RTSP server. When the client disconnects, the media gets
> destroyed.
> I do however, keep a pointer to my appsrc element somewhere.
> 
> How can I check if the element hasn't been destroyed?
> I've tried G_IS_OBJECT but that just returns true even though the element
> was destroyed...
> 
> For now I just keep a boolean member of my class and set and unset it using
> the /media-configured/, and /unprepared/ signals, but that just seems wrong.

You could use a `GWeakRef` for this. It will not keep the object alive
but allows you to safely get a strong reference to it when needed, and
would return `NULL` if the object disappeared in the meantime.

-- 
Sebastian Dröge, Centricular Ltd · https://www.centricular.com




More information about the gstreamer-devel mailing list