keep obj reference to avoid GC in serializing for C ext

modify from c5aa8054bea417a350c970cd9b2c8acc8f5e2467, thanks to Leon