Skip to content

Commit c4e3a03

Browse files
committed
docs/gc: Document gc.threshold() function.
1 parent 4cdddfe commit c4e3a03

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

docs/library/gc.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,27 @@ Functions
3838
:class: attention
3939

4040
This function is MicroPython extension.
41+
42+
.. function:: threshold([amount])
43+
44+
Set or query additional GC allocation threshold. Normally, GC is
45+
triggered when new allocation cannot be satisfied, i.e. on out of
46+
memory (OOM) condition. If this function is called, in addition to
47+
OOM, GC will be triggered each time after *amount* of bytes has been
48+
allocated (in total, since the previous time such amount of bytes
49+
had been allocated). *amount* is usually specified as less than the
50+
full heap size, with the intention to trigger GC earlier than the
51+
heap will be exhausted, and in the hope that early GC will prevent
52+
excessive memory fragmentation. This is a heuristic measure, effect
53+
of which will vary from an application to application, as well as
54+
the optimal value of *amount* parameter.
55+
56+
Calling the function without argument will return current value of
57+
the threshold. Value of -1 means a disabled allocation threshold.
58+
59+
.. admonition:: Difference to CPython
60+
:class: attention
61+
62+
This function is MicroPython extension. CPython has a similar
63+
function - ``set_threshold()``, but due to different GC
64+
implementations, its signature and semantics are different.

0 commit comments

Comments
 (0)