PyO3 中对象向量的垃圾收集
Garbage collection for vector of object in PyO3
我有 2 个 pyclasses Block
和 BlockGroup
。
#[pyclass]
struct Block {
start: i32,
stop: i32,
}
#[pyclass]
struct BlockGroup {
blocks: Vec<Block>
}
我是 PyO3 的新手,我已经阅读了 documentation 关于垃圾收集的内容,但我并不完全理解它。
If your type owns references to other python objects, you will need to
integrate with Python's garbage collector so that the GC is aware of
those references.
鉴于 BlockGroup
拥有具体的 Block
个对象,我是否需要实施自定义垃圾收集?
在这种情况下,Block
和 Vec<Block>
分别是 rust 内存的一部分而不是 python 的内存,因此您无需担心垃圾回收。 python 内存中的对象将例如是 Py<Block>
。
我有 2 个 pyclasses Block
和 BlockGroup
。
#[pyclass]
struct Block {
start: i32,
stop: i32,
}
#[pyclass]
struct BlockGroup {
blocks: Vec<Block>
}
我是 PyO3 的新手,我已经阅读了 documentation 关于垃圾收集的内容,但我并不完全理解它。
If your type owns references to other python objects, you will need to integrate with Python's garbage collector so that the GC is aware of those references.
鉴于 BlockGroup
拥有具体的 Block
个对象,我是否需要实施自定义垃圾收集?
在这种情况下,Block
和 Vec<Block>
分别是 rust 内存的一部分而不是 python 的内存,因此您无需担心垃圾回收。 python 内存中的对象将例如是 Py<Block>
。