Optimizing for memory with images

Hi,

I can clearly see that it’s starting to make sense!

Indeed it’s exactly what I (and others, @micycle @noel ) were suggesting. :wink:

Note that the garbage collector is not instantly releasing a previous overwritten PImage. It’s up to the JVM (Java virtual machine, running the bytecode produced by the Java compiler) to decide when to free the previous image. Anyway it’s going to greatly reduce memory usage!

I found those useful StackOverflow links about garbage collector and how to deal with it :

For your last question, this is just a question of clarity and style because this is equivalent in terms of result. For future code readers, you can add comments but at this point of the project is probably not necessary.

If you were worried about memory for creating an intermediate variable, you are creating it in a for loop, therefore it’s in a local scope meaning that as soon as you go out of the block (at the next iteration), the object can be freed from memory by the garbage collector. And also thousands of String is not that much.