MCPcopy Create free account
hub / github.com/Dispatcharr/Dispatcharr / trim_c_allocator_heap

Function trim_c_allocator_heap

core/utils.py:549–565  ·  view source on GitHub ↗

Return unused C heap pages to the OS where supported (glibc malloc_trim).

()

Source from the content-addressed store, hash-verified

547 return wrapper
548
549def trim_c_allocator_heap():
550 """Return unused C heap pages to the OS where supported (glibc malloc_trim)."""
551 try:
552 import ctypes
553 import ctypes.util
554
555 libc_name = ctypes.util.find_library("c")
556 if not libc_name:
557 return False
558 libc = ctypes.CDLL(libc_name)
559 if not hasattr(libc, "malloc_trim"):
560 return False
561 libc.malloc_trim(0)
562 return True
563 except Exception:
564 logger.debug("malloc_trim unavailable or failed", exc_info=True)
565 return False
566
567
568def cleanup_memory(log_usage=False, force_collection=True):

Callers 2

_runFunction · 0.85

Calls

no outgoing calls