18 lines
444 B
Python
18 lines
444 B
Python
"""Best-effort return of idle allocator memory after large operations."""
|
|
import ctypes
|
|
import gc
|
|
import sys
|
|
|
|
|
|
def release_idle_memory():
|
|
gc.collect()
|
|
if sys.platform == 'linux':
|
|
try:
|
|
trim = ctypes.CDLL(None).malloc_trim
|
|
trim.argtypes = [ctypes.c_size_t]
|
|
trim.restype = ctypes.c_int
|
|
return bool(trim(0))
|
|
except (AttributeError, OSError):
|
|
pass
|
|
return False
|