[DBUS] g_dbus_method_invocation_return_value 함수에 대한 고찰
2025. 12. 23. 01:15■ g_dbus_method_invocation_return_value 함수 시그니처
void
g_dbus_method_invocation_return_value (GDBusMethodInvocation *invocation,
GVariant *parameters);
- 파라미터의 reference count는 하나가 줄어 든다. 즉, unref를 따로 안해도 된다. GVariant 설명을 참고해보자
출처: https://github.com/GNOME/glib/blob/main/gio/gdbusmethodinvocation.c#L530
출처:https://docs.gtk.org/gio/method.DBusMethodInvocation.return_value.html))
출처: https://docs.gtk.org/glib/struct.Variant.html
출처: https://docs.gtk.org/glib/method.Variant.is_floating.html
- g_dbus_method_invocation_return_value 함수가 호출되면, 이 함수가 invocation에 대한 소유권을 가져간다. 즉 invocation도 reference count가 하나가 줄어 든다.
(This method will take ownership of invocation.
출처:https://docs.gtk.org/gio/method.DBusMethodInvocation.return_value.html)
- g_object_ref
이 함수는 object에 대한 reference count를 증가한다. 이 함수가 중요한 이유는 g_object_unref로 인해 (혹은 내부적으로 이 함수를 호출하는 함수가 있을 수 있다) reference 카운트가 감소되어 메모리가 free될 수 도 있기 때문이다.
따라서, 예기치않은 메모리 해제를 막기위해 gdbus관련 객체를 참조하게 될 경우, 명시적으로 g_object_ref를 써주자.
- g_object_unref가 메모리 해제하는 부분
g_object_unref의 구현부(https://github.com/GNOME/glib/blob/main/gobject/gobject.c#L4920)
g_type_free_instance 호출 -> g_free_sized 호출 -> free 호출
