mirror of
https://github.com/pybind/pybind11.git
synced 2026-05-21 21:39:33 +00:00
Implement reference_internal with a keep_alive
reference_internal requires an `instance` field to track the returned reference's parent, but that's just a duplication of what keep_alive<0,1> does, so use a keep alive to do this to eliminate the duplication.
This commit is contained in:
@@ -95,3 +95,17 @@ print_NestA(c.b.a)
|
||||
print_NestB(b)
|
||||
print_NestB(c.b)
|
||||
print_NestC(c)
|
||||
abase = a.as_base()
|
||||
print(abase.value)
|
||||
a.as_base().value += 44
|
||||
print(abase.value)
|
||||
print(c.b.a.as_base().value)
|
||||
c.b.a.as_base().value += 44
|
||||
print(c.b.a.as_base().value)
|
||||
del c
|
||||
gc.collect()
|
||||
del a # Should't delete while abase is still alive
|
||||
gc.collect()
|
||||
print(abase.value)
|
||||
del abase
|
||||
gc.collect()
|
||||
|
||||
Reference in New Issue
Block a user