public void TestNativeObjectReferenceCounting()
        {
            Dog dog = new Dog();

            Assert.Equal(1, dog.ReferenceCount);
            Assert.Equal(1, dog.NativeReferenceCount);
            dog.AddRef();
            Assert.Equal(2, dog.ReferenceCount);
            Assert.Equal(1, dog.NativeReferenceCount);
            DogOwner owner = new DogOwner(dog);

            Assert.Equal(1, owner.ReferenceCount);
            Assert.Equal(3, dog.ReferenceCount);
            Assert.Equal(1, dog.NativeReferenceCount);
            dog.Release();
            Assert.Equal(1, owner.ReferenceCount);
            Assert.Equal(2, dog.ReferenceCount);
            Assert.Equal(1, dog.NativeReferenceCount);
            dog.Release();
            Assert.Equal(1, owner.ReferenceCount);
            Assert.Equal(1, owner.NativeReferenceCount);
            Assert.Equal(1, dog.ReferenceCount);
            Assert.Equal(1, dog.NativeReferenceCount);
            Assert.False(dog.IsInvalid);
            owner.SayWalk();
            owner.Release();
            Assert.Equal(0, owner.ReferenceCount);
            Assert.Equal(0, dog.ReferenceCount);
            // Cannot check on the native ref count - deleted objects.
            // TODO think of a simple way to test these
            //Assert.Equal(0, owner.NativeReferenceCount);
            //Assert.Equal(0, dog.NativeReferenceCount);
            Assert.True(dog.IsInvalid);
            Assert.True(owner.IsInvalid);
        }
        internal void say_walk(DogOwner owner)
        {
            IntPtr objPtr = owner.GetHandle();

            NativeLib.GetFunction <say_walk_delegate>("say_walk")(objPtr);
        }
        internal int get_dog_owner_refcount(DogOwner owner)
        {
            IntPtr objPtr = owner.GetHandle();

            return(NativeLib.GetFunction <get_dog_owner_refcount_delegate>("get_owner_refcount")(objPtr));
        }