[Fix #7674] Transfer ownership of layer to C++ when added to the registry