Reference cycle between GIRepository and GIBaseInfos cached by it
Discovered while debugging !3843 (merged).
gi_repository_find_by_type()
, gi_repository_find_by_error_domain()
, and gi_repository_get_object_gtype_interfaces()
cache their results in the hash tables
GIRepositoryPrivate.info_by_gtype
, GIRepositoryPrivate.info_by_error_domain
, and GIRepositoryPrivate.interfaces_for_gtype
, respectively.
These hash tables hold references to the info objects (e.g., girepository.c:921.) The info objects themselves hold references to the repository (gibaseinfo.c:359.
I haven't extracted out a standalone reproducer from !3843 (merged) yet but this code may work:
#include <girepository.h>
int main(void) {
GError *error = NULL;
GIRepository *repo = gi_repository_new();
g_assert(repo);
gi_repository_require(repo, "GObject", "2.0", 0, &error);
g_assert(!error);
GIBaseInfo *info = gi_repository_find_by_gtype(repo, G_TYPE_OBJECT);
g_assert(info);
gi_base_info_unref(info);
g_object_unref(repository);
return 0;
}