简体   繁体   中英

Garbage collection for vector of object in PyO3

I have 2 pyclasses Block and BlockGroup .

#[pyclass]
struct Block {
    start: i32,
    stop: i32,
}

#[pyclass]
struct BlockGroup {
    blocks: Vec<Block>
}

I'm new to PyO3 and I have read the documentation about garbage collection but I don't completely grok it.

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.

Given that BlockGroup owns concrete Block objects, do I need to implement custom garbage collection?

In this case, Block and Vec<Block> respectively are part of rust's memory and not python's memory, so you don't need to worry about garbage collection. A object in python's memory would eg be Py<Block> .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM