How to Flush GIMP Memory Cache Using Scripts
This guide explains how to release GIMP's internal memory and undo caches during automated or long-running tasks without restarting the application. You will learn the specific Procedure Database (PDB) commands available for both Script-Fu and Python-Fu that purge accumulated image data and reclaim system RAM.
The primary command to force GIMP to flush its internal memory caches
for an active image is
gimp-image-undo-free in Script-Fu, or
pdb.gimp_image_undo_free(image) in
Python-Fu.
Why Memory Accumulates in GIMP
GIMP retains image operations, tile swap data, and intermediate layer modifications inside an internal undo buffer to allow users to revert actions. In batch operations and heavy scripting workflows, this cache is not automatically purged while the image remains open, causing memory usage to climb until the host system exhausts available RAM.
Using the Command
Script-Fu (Scheme)
In Script-Fu, call the procedure by passing the target image identifier:
(gimp-image-undo-free image)Python-Fu
In Python-Fu, access the command through the Procedure Database interface:
pdb.gimp_image_undo_free(image)Executing this command instantly purges the undo history buffer assigned to that image, freeing the underlying GEGL tile caches and RAM allocations while keeping the image open for continued processing.
Additional Memory Management Commands
To manage memory proactively during intense batch scripts, consider
combining gimp-image-undo-free with these complementary PDB
commands:
- Preventing Cache Growth
(
gimp-image-undo-disable/gimp-image-undo-enable): If you are running multiple sequential operations and do not need undo points, disable undo recording completely at the start of your script usingpdb.gimp_image_undo_disable(image)and re-enable it at the end withpdb.gimp_image_undo_enable(image). - Complete Memory Release
(
gimp-image-delete): When an image is no longer needed, close and purge it entirely from RAM usingpdb.gimp_image_delete(image). Simply closing a display view does not always unload the image data from GIMP's core memory.