G_object_set_data() and unbounded growth of the GQuark storage

I have a question concerning g_object_set_data(). The documentation says:

Internally, the key is converted to a GQuark using g_quark_from_string(). This means a copy of key is kept permanently (even after object has been finalized) — so it is recommended to only use a small, bounded set of values for key in your program, to avoid the GQuark storage growing unbounded.

If I have a program that continuously sets the same key (let’s call it "my_key") to always new GObjects, does this mean that the GQuark storage will keep growing unbounded? Or do I have to assign different keys (let’s say "my_key_1", "my_key_2", "my_key_3", …) for this to happen?

The documentation seems to suggest that the unbounded growth happens only in case of different strings for the key name ( "my_key_1", "my_key_2", "my_key_3", …), but I am not completely sure.

See the referenced g_quark_from_string() function:

If the string does not currently have an associated GQuark , a new GQuark is created, using a copy of the string.

That is, if string does have an associated GQuark, no new GQuark is created.

1 Like

Thanks a lot, Florian! Maybe copying that sentence from the documentation of g_quark_from_string() to the documentation of g_object_set_data() will do more good than harm :slight_smile:

It’s not hard to follow a single link. g_quark_from_string() is already referenced by g_object_set_data() (although the link might currently be broken on the docs website due to the ongoing docs website refresh; it should normally be hyperlinked).

The cross-link is already broken in the old docs, because it crosses module boundaries and library-web was broken.

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