Skip to content

Commit

Permalink
Merge #2864
Browse files Browse the repository at this point in the history
2864: Add a section on memory management for `extension` r=davidhewitt a=haixuanTao

Adding a special case of memory management when writing an extension.

This is a documentation of: #1056 and #2853


Co-authored-by: Haixuan Xavier Tao <[email protected]>
Co-authored-by: David Hewitt <[email protected]>
  • Loading branch information
3 people authored Jan 10, 2023
2 parents 34b9445 + eea2a31 commit 02fa6b8
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions guide/src/memory.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ dropped you do not retain access to any owned references created after the
[documentation for `Python::new_pool()`]({{#PYO3_DOCS_URL}}/pyo3/prelude/struct.Python.html#method.new_pool)
for more information on safety.

This memory management can also be applicable when writing extension modules.
`#[pyfunction]` and `#[pymethods]` will create a `GILPool` which lasts the entire
function call, releasing objects when the function returns. Most functions only create
a few objects, meaning this doesn't have a significant impact. Occasionally functions
with long complex loops may need to use `Python::new_pool` as shown above.

This behavior may change in future, see [issue #1056](https://github.com/PyO3/pyo3/issues/1056).

## GIL-independent memory

Sometimes we need a reference to memory on Python's heap that can outlive the
Expand Down

0 comments on commit 02fa6b8

Please sign in to comment.