Can i de-load or selectively load in images?

Im having performance problems in my application due to i believe a lot of different images and files being loaded in at once.

My program starts off fast, but gets slower over time. I believe this is a memory issue and not a CPU issue. I know for a fact i dont have any growing number sets, and i noticed a huge difference in performance after deleting swaths of files even if there was no difference in performance when just not running through them.

So is it possible to “unload” or “deload” images when im not using them, then “reload” them if i am?

I couldnt find any functions anywhere to do what im trying to do.

I saw a .remove() function, but im not sure if this is related to what I am trying to do.

Is it possible to do what I am trying to do?

EDIT: Problem is solved.

  1. No, I cannot manually deload and reload images. Javascript does this for you. However, this was not the problem as i had suspected.

  2. After some process-of-elimination with trying to find where a memory leak could be located, I had discovered in a part of my program, I called “push()” twice but “pop()” only once. Upon removing the duplicate “push()”, my program was no longer slowing down after ten-fifteen minutes. This must have been the main source of the memory leak. Weirdly though, the p5js editor never gave me an error message for this mistake. FYI for all you noob p5js coders, don’t make this mistake.

It’s not possible to actively free memory. Javascript frees memory automatically in the background. It’s called garbage collection. So you need to loose all references to the image and then at some point javascript frees the memory.

Loading images should not cause memory leaks. Without seeing the code it’s impossible to say if images get copied or if there’s some other event that consumes memory.

1 Like