pybind11/example/example-keep-alive.py
Glen Walker f45bb585c3 Support keep_alive where nurse may be None
For example keep_alive<0,1>() should work where the return value may sometimes be None. At present a "Could not allocate weak reference!" exception is thrown.
Update documentation to clarify behaviour of keep_alive when nurse is None or does not support weak references.
2016-08-18 09:09:41 +12:00

68 lines
885 B
Python

from __future__ import print_function
import sys
import gc
sys.path.append('.')
from example import Parent, Child
if True:
p = Parent()
p.addChild(Child())
gc.collect()
print(p)
p = None
gc.collect()
print("")
if True:
p = Parent()
p.returnChild()
gc.collect()
print(p)
p = None
gc.collect()
print("")
if True:
p = Parent()
p.addChildKeepAlive(Child())
gc.collect()
print(p)
p = None
gc.collect()
print("")
if True:
p = Parent()
p.returnChildKeepAlive()
gc.collect()
print(p)
p = None
gc.collect()
print("")
if True:
p = Parent()
p.returnNullChildKeepAliveChild()
gc.collect()
print(p)
p = None
gc.collect()
print("")
if True:
p = Parent()
p.returnNullChildKeepAliveParent()
gc.collect()
print(p)
p = None
gc.collect()
print("")
print("Terminating..")