core: Free registry resources before unreffing it

We can't unref the registry to finalize all the sources and plugins, because
they can try to access the registry again in their finalize method.

This commit first finalizes the sources, plugins, and other resources, and at
the end it unrefs the registry.

https://bugzilla.gnome.org/show_bug.cgi?id=724660