Async operation source-object ref count

Hi,

While performing an async i/o on a source-object ( Eg. GFile ), whose responsibility is it to keep the source-object alive when the GAsyncReadyCallback is invoked.

Looks like GFile async operations use GTask currently for achieving async capability. GTask ref counts the source-object on creation and unrefs upon finalize, after GAsyncReadyCallback is invoked. So, it does appear the g_file_* functions take care of the ref count here. But, that is an implementation detail.

Currently, there is no mention of who maintains ref count in the GLib API documentation.

Thanks!

1 Like

Tracked in https://gitlab.gnome.org/GNOME/glib/-/issues/2343

1 Like

Not sure if this is explicitly documented anywhere, but it is not just an implementation details. It is an expected aspected of the async pattern that is prevalent in GIO and the GTK stack that “the system” keeps a reference to the source object until after finish().

1 Like

The main issue was to know, what is the best place to unref the source object ?

Because in some GNOME projects, I saw this being done in the callback, and in others immediately after the async call. Some minimal documentation should have cleared this issue.

Doc issue is now tracked in glib#2343.

Thanks!

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