@@ -486,6 +486,21 @@ As this may not be trivial, we recommend to write an issue in ``pyfakefs`` with
486486We will analyze the problem, and if we find a solution we will either get this fixed in ``pyfakefs ``
487487(if it is related to a commonly used module), or help you to resolve it.
488488
489+ Contiguous tests use large amounts of memory
490+ --------------------------------------------
491+ If you are creating very large fake files in your tests, these files will live in memory.
492+ If running several such tests contiguously, it is not guaranteed that the memory for these files is
493+ freed, even if the filesystem is created anew. Some references to them may only be removed by the
494+ garbage collector from time to time.
495+ Under conditions with restricted memory (like in docker containers) this may cause out of memory
496+ errors or, more likely, a freeze of the system.
497+ If you encounter such a problem, there are several possibilities how to handle this:
498+
499+ * rewrite your tests to avoid the need for such large files
500+ * if you only use the files to fill the filesystem and don't need to access their contents, use
501+ the `st_size ` option of `create_file `, which does not allocate the memory
502+ * if you really need the large files, call `gc.collect `_ between tests to ensure that the
503+ garbage collector cleans up the memory
489504
490505.. _`multiprocessing` : https://docs.python.org/3/library/multiprocessing.html
491506.. _`subprocess` : https://docs.python.org/3/library/subprocess.html
@@ -497,3 +512,4 @@ We will analyze the problem, and if we find a solution we will either get this f
497512.. _`xlrd` : https://pypi.org/project/xlrd/
498513.. _`openpyxl` : https://pypi.org/project/openpyxl/
499514.. _`importlib.metadata` : https://docs.python.org/3/library/importlib.metadata.html
515+ .. _`gc.collect` : https://docs.python.org/3/library/gc.html#gc.collect
0 commit comments