diff --git a/src/IECorePython/RefCountedBinding.cpp b/src/IECorePython/RefCountedBinding.cpp index 56d0fd002e..43ba18730c 100644 --- a/src/IECorePython/RefCountedBinding.cpp +++ b/src/IECorePython/RefCountedBinding.cpp @@ -78,6 +78,7 @@ void bindRefCounted() .def( "__ne__", notEqual ) .def( "__hash__", hash ) .def( "isSame", &is ) + .def( "refCount", &RefCounted::refCount ) .def( "numWrappedInstances", &WrapperGarbageCollector::numWrappedInstances ).staticmethod( "numWrappedInstances" ) .add_static_property( "garbageCollectionThreshold", &WrapperGarbageCollector::getCollectThreshold, &WrapperGarbageCollector::setCollectThreshold ) .def( "collectGarbage", &WrapperGarbageCollector::collect ).staticmethod( "collectGarbage" ) diff --git a/test/IECore/RefCountedTest.py b/test/IECore/RefCountedTest.py index 1b2aa6dc66..366b07739d 100644 --- a/test/IECore/RefCountedTest.py +++ b/test/IECore/RefCountedTest.py @@ -151,5 +151,18 @@ def testUseAsKey( self ) : self.assertEqual( d[p2], "p2" ) self.assertEqual( d[c["p2"]], "p2" ) + def testRefCount( self ) : + + c = IECore.CompoundData() + i = IECore.IntData( 10 ) + + r = i.refCount() + + c["i"] = i + self.assertEqual( i.refCount(), r + 1 ) + + del c["i"] + self.assertEqual( i.refCount(), r ) + if __name__ == "__main__": unittest.main()