|
| 1 | +""" |
| 2 | +Control the garbage collector. |
| 3 | +
|
| 4 | +MicroPython module: https://docs.micropython.org/en/v1.27.0/library/gc.html |
| 5 | +
|
| 6 | +CPython module: :mod:`python:gc` https://docs.python.org/3/library/gc.html . |
| 7 | +
|
| 8 | +--- |
| 9 | +Module: 'gc' on micropython-v1.27.0-stm32-PYBV11-NETWORK |
| 10 | +""" |
| 11 | + |
| 12 | +# MCU: {'variant': 'NETWORK', 'build': '', 'arch': 'armv7emsp', 'port': 'stm32', 'board': 'PYBV11', 'board_id': 'PYBV11-NETWORK', 'mpy': 'v6.3', 'ver': '1.27.0', 'family': 'micropython', 'cpu': 'STM32F405RG', 'version': '1.27.0'} |
| 13 | +# Stubber: v1.26.4 |
| 14 | +from __future__ import annotations |
| 15 | +from _typeshed import Incomplete |
| 16 | +from typing import overload |
| 17 | +from typing_extensions import Awaitable, TypeAlias, TypeVar |
| 18 | + |
| 19 | +def mem_alloc() -> int: |
| 20 | + """ |
| 21 | + Return the number of bytes of heap RAM that are allocated by Python code. |
| 22 | +
|
| 23 | + Admonition:Difference to CPython |
| 24 | + :class: attention |
| 25 | +
|
| 26 | + This function is MicroPython extension. |
| 27 | + """ |
| 28 | + ... |
| 29 | + |
| 30 | +def isenabled(*args, **kwargs) -> Incomplete: ... |
| 31 | +def mem_free() -> int: |
| 32 | + """ |
| 33 | + Return the number of bytes of heap RAM that is available for Python |
| 34 | + code to allocate, or -1 if this amount is not known. |
| 35 | +
|
| 36 | + Admonition:Difference to CPython |
| 37 | + :class: attention |
| 38 | +
|
| 39 | + This function is MicroPython extension. |
| 40 | + """ |
| 41 | + ... |
| 42 | + |
| 43 | +@overload |
| 44 | +def threshold() -> int: |
| 45 | + """ |
| 46 | + Set or query the additional GC allocation threshold. Normally, a collection |
| 47 | + is triggered only when a new allocation cannot be satisfied, i.e. on an |
| 48 | + out-of-memory (OOM) condition. If this function is called, in addition to |
| 49 | + OOM, a collection will be triggered each time after *amount* bytes have been |
| 50 | + allocated (in total, since the previous time such an amount of bytes |
| 51 | + have been allocated). *amount* is usually specified as less than the |
| 52 | + full heap size, with the intention to trigger a collection earlier than when the |
| 53 | + heap becomes exhausted, and in the hope that an early collection will prevent |
| 54 | + excessive memory fragmentation. This is a heuristic measure, the effect |
| 55 | + of which will vary from application to application, as well as |
| 56 | + the optimal value of the *amount* parameter. |
| 57 | +
|
| 58 | + Calling the function without argument will return the current value of |
| 59 | + the threshold. A value of -1 means a disabled allocation threshold. |
| 60 | +
|
| 61 | + Admonition:Difference to CPython |
| 62 | + :class: attention |
| 63 | +
|
| 64 | + This function is a MicroPython extension. CPython has a similar |
| 65 | + function - ``set_threshold()``, but due to different GC |
| 66 | + implementations, its signature and semantics are different. |
| 67 | + """ |
| 68 | + |
| 69 | +@overload |
| 70 | +def threshold(amount: int) -> None: |
| 71 | + """ |
| 72 | + Set or query the additional GC allocation threshold. Normally, a collection |
| 73 | + is triggered only when a new allocation cannot be satisfied, i.e. on an |
| 74 | + out-of-memory (OOM) condition. If this function is called, in addition to |
| 75 | + OOM, a collection will be triggered each time after *amount* bytes have been |
| 76 | + allocated (in total, since the previous time such an amount of bytes |
| 77 | + have been allocated). *amount* is usually specified as less than the |
| 78 | + full heap size, with the intention to trigger a collection earlier than when the |
| 79 | + heap becomes exhausted, and in the hope that an early collection will prevent |
| 80 | + excessive memory fragmentation. This is a heuristic measure, the effect |
| 81 | + of which will vary from application to application, as well as |
| 82 | + the optimal value of the *amount* parameter. |
| 83 | +
|
| 84 | + Calling the function without argument will return the current value of |
| 85 | + the threshold. A value of -1 means a disabled allocation threshold. |
| 86 | +
|
| 87 | + Admonition:Difference to CPython |
| 88 | + :class: attention |
| 89 | +
|
| 90 | + This function is a MicroPython extension. CPython has a similar |
| 91 | + function - ``set_threshold()``, but due to different GC |
| 92 | + implementations, its signature and semantics are different. |
| 93 | + """ |
| 94 | + |
| 95 | +def collect() -> None: |
| 96 | + """ |
| 97 | + Run a garbage collection. |
| 98 | + """ |
| 99 | + ... |
| 100 | + |
| 101 | +def enable() -> None: |
| 102 | + """ |
| 103 | + Enable automatic garbage collection. |
| 104 | + """ |
| 105 | + ... |
| 106 | + |
| 107 | +def disable() -> None: |
| 108 | + """ |
| 109 | + Disable automatic garbage collection. Heap memory can still be allocated, |
| 110 | + and garbage collection can still be initiated manually using :meth:`gc.collect`. |
| 111 | + """ |
| 112 | + ... |
0 commit comments