To add up to the excellent answer from @wstcegg, what worked for me to clean my GPU cache on Ubuntu (did not work under windows) was using:
For more details about garbage collection, see this good reference, which I am quoting the interesting part hereinafter
Why Perform Manual Garbage Collection?
We know that the Python interpreter keeps a track of references to
objects used in a program. In earlier versions of Python (until
version 1.6), the Python interpreter used only the reference counting
mechanism to handle memory. When the reference count drops to zero,
the Python interpreter automatically frees the memory. This classical
reference counting mechanism is very effective, except that it fails
to work when the program has reference cycles. A reference cycle
happens if one or more objects are referenced each other, and hence
the reference count never reaches zero.
Let's consider an example.
>>> def create_cycle():
... list = [8, 9, 10]
... list.append(list)
... return list
...
>>> create_cycle()
[8, 9, 10, [...]]
The above code creates a reference cycle, where the object list refers
to itself. Hence, the memory for the object list will not be freed
automatically when the function returns. The reference cycle problem
can't be solved by reference counting. However, this reference cycle
problem can be solved by change the behavior of the garbage collector
in your Python application.
To do so, we can use the gc.collect() function of the gc module.
import gc
n = gc.collect()
print("Number of unreachable objects collected by GC:", n)
The gc.collect() returns the number of objects it has collected and
de-allocated.
There are two ways to perform manual garbage collection: time-based or
event-based garbage collection.
Time-based garbage collection is pretty simple: the gc.collect()
function is called after a fixed time interval.