Memory usage increases as images are loaded. Help me

PImage fig_image;
long TIMER_RE = 0;

void setup(){
  size(1000,1000);
  fig_image  = loadImage("fig_image.jpg"); 
  
}

void draw(){
  if(TIMER_RE < millis()){
     TIMER_RE = millis()+1000;
     fig_image  = loadImage("fig_image.jpg");     
  } 
  image(fig_image,0,0,width,height);
}

There is only one image variable, so why does the PC’s memory keep increasing? Any solution?

a1

a2

Images are often loaded. However, I don’t know why the ‘PC memory’ keeps increasing even though there is only one image stored in the variable.

Any solution?

removecache()

3 Likes

Hi

Try to make timer like this

int start;
int end ;
void setup() {
  size(400,400);
  
}

void draw() {
  //background(0);
  start = millis() - end;
  if (start >= 500) {
    end = millis();
  rect(10, 10, 180, 180);
}
}

1 Like

Hi

I think you keep loop load image in void draw() thats why your memory low

1 Like

@jafal
Thank you for answer.
However, that’s not what I want.
This is the implementation of the above source code for testing.

1 Like

@GoToLoop
Thank you for answer.
There is a source code that can solve it. The problem is the delay.

there is a problem with lag.

void draw() {
  if(TIMER_RE < millis()){
     TIMER_RE = millis()+1000;     
     fig_image = null; System.gc();
     fig_image = loadImage("fig_image.jpg");   
  } 
  image(fig_image, 0, 0, width, height);
}

@GoToLoop

I am making a ‘viewer program’ that allows you to zoom in and out through an image.
If you use ‘System.gc();’ like the video, a delay problem occurs.

If so, do you have any solution?

As seen in the video above,
‘System.gc();’ If you use , there will be lag.
The current implementation was made using the ‘get’ function in ‘image’.
If you have any solution, please let me know.