私はlecture on GTK+ memory managementの "オブジェクト降順GInitiallyUnown
"の章を読んでいます。浮動参照の概念は、私たちはコードGObjectへの浮動参照への代替方法
container = create_container();
container_add_child(container, create_child());
代わりの
Child *child;
container = create_container();
child = create_child();
container_add_child(container, child);
g_object_unref(child);
を書くことができます導入された私はすぐに次のように同じことが実現することができることに気づきました。機能はcontainer_add_child_move_ownership
です。 container_add_child
は余分です。 container_add_child_move_ownership(container, child)
が発信者からcontainer
に所有権を移動したとします。したがって、container_add_child_move_ownership
は参照カウントを変更しません。したがって、次の例は正しいです。
void f(Container *container) {
container_add_child_move_ownership(container, create_child());
}
0)私の解決策は、私が表示されていない欠陥を持っている、または1)浮動参照の概念は悪いデザインの決定であるのどちらか。それは本当ですか?