MV Clean the img cache through script

Hi~
I'm using a plugin to preload some pictures (using script calls) into cache before showing them (to avoid that awful flickering).
But I feel I need to clear the cache after doing that.
I tried to do it with this script, which I had found in another thread:
Code:
ImageManager.cache._inner["img/pictures/exp1.png:0"].free()
but the console returns me this error:
Spoiler: Error
error.PNG
So I guess I'm doing something wrong 😐
How can I clear the cache by deleting specific pictures?
you're correct in your assumptions - but not entirely.

yes, any preloader is a memory leak waiting to happen and the resources need to be removed later.
But "of undefined" means that the object you're trying to handle does not exist.

This could either be because it is not yet loaded, because it has already been deleted or because you got the syntax wrong.
I can't say anything about the syntax, but there is a so-called garbage collector that automatically clears memory of older, unused objects.
There is a chance that this already happened when you try to call the functions - but that depends on how the preloader works because it is possible that the preloader blocks the preloaded resources permanently like you originally assumed.
Thanks for your answer.
In theory, I preload pictures, I run the animation and right after I try to clean, so, unless the garbage collector is really quick at its job, I don't think that's the problem (but I can still be wrong)...
Could the problem be that I preload using a plugin-related script call and then I try to clean with this more..."generic" one?
However...it is not strictly necessary for me to use this plugin, so I can also change my request in: there is a way to preload specific pictures and then clean the cache (without plugins, maybe just scripts)?
I imagine the actual problem here is that the default image cache (10 MPix) is too small for your game. If you try to cache a new image that takes the total size over the limit, cache entries will be deleted, starting with the least recently-referenced entry, until the total size falls below the limit. You can increase the image cache size with a plugin, e.g. Community_Basic (included in new projects).

The newest version of RMMV should request/load relevant images when an event starts: it scans the commands of the event and requests pretty much any visual assets it finds. However, it iterates from start to finish, so if your event requests more than an entire image cache worth of images, then this will often be wasted effort. (RMMZ gets around this by only looking at the first 200 commands.)

If you want to load an img/picture file into the cache, you can use something like this:
JavaScript:
ImageManager.requestPicture('exp1');
Each image type has its own request method, check rpg_managers.js lines 1003~1057 for details.

A preloader plugin will typically implement its own cache(s), in which case you will need to clear it with code specific to that plugin.

Original thread: https://forums.rpgmakerweb.com/threads/clean-the-img-cache-through-script.139773/