Skip to content

Commit 6e78419

Browse files
committed
Minor documentation.
1 parent f9df73a commit 6e78419

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

doc/sphinx/source/memory_leaks.rst

+16-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,22 @@
1414
Memory Leaks
1515
===============================================
1616

17-
Memory leaks.
17+
18+
Tools for Detecting Memory Leaks
19+
------------------------------------
20+
21+
22+
``pymemtrace``
23+
^^^^^^^^^^^^^^^^^^^^^^^^^^
24+
25+
26+
The ``pymemtrace`` package contains a number of tools (written by me) that help detect memory usage and leaks.
27+
The documentation contains advice on handling memory leaks.
28+
29+
* On PyPi: `<https://pypi.org/project/pymemtrace/>`_
30+
* Project: `<https://github.com/paulross/pymemtrace>`_
31+
* Documentation: `<https://pymemtrace.readthedocs.io/en/latest/index.html>`_
32+
1833

1934
.. note::
2035

doc/sphinx/source/refcount.rst

+7-9
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,12 @@ The append operation *must* behave this way, consider this Python code
394394
l = []
395395
a = 400
396396
# The integer object '400' has a reference count of 1 as only
397-
# one symbol references it: ``a``.
397+
# one symbol references it: a.
398398
l.append(a)
399399
# The integer object '400' must now have a reference count of
400-
# 2 as two symbols reference it: ``a`` and ``l``,
401-
# specifically ``l[-1]``.
400+
# 2 as two symbols reference it: a and l, specifically l[-1].
402401
403-
The fix for this code is to do this, error checking omitted:
402+
The fix is to create a temporary item and then decref *that* once appended (error checking omitted):
404403

405404
.. code-block:: c
406405
@@ -411,14 +410,13 @@ The fix for this code is to do this, error checking omitted:
411410
for (int i = 400; i < 405; ++i) {
412411
/* Create the object to append to the list. */
413412
temporary_item = PyLong_FromLong(i);
414-
/* Append it. This will increment the reference count. */
413+
/* temporary_item->ob_refcnt == 1 now */
414+
/* Append it. This will increment the reference count to 2. */
415415
PyList_Append(list, temporary_item);
416416
/* Decrement our reference to it leaving the list having the only reference. */
417417
Py_DECREF(temporary_item);
418-
/* Implementation detail really. */
419-
assert(temporary_item->ob_refcnt == 1);
420-
/* Good practice... */
421-
temporary_item = NULL;
418+
/* temporary_item->ob_refcnt == 1 now */
419+
temporary_item = NULL; /* Good practice... */
422420
}
423421
Py_RETURN_NONE;
424422
}

0 commit comments

Comments
 (0)