Mac compiling errors - object backing the pointer ... will be destroyed at the end of the full-expression [-Werror,-Wdangling-assignment]

Finally I fixed this by adding additional compiler flags to the target.cs files of the project.