Free RAM memory in Java [closed]

-1

I have an infinite loop that performs a series of operations with different types of files, reads files, creates different xml and inserts it into a database. For this I use the following code:

    public static void main(String[] args) throws IOException {

          Thread_WKAS  miRunnable = new Thread_WKAS();
          Thread hilo1= new Thread(miRunnable);

         hilo1.start();
    } 
    private static class Thread_WKAS implements Runnable{
      public void run() {
         while (true){

          leer_archivos_crear_archivos_insertar_registros();

          System.gc();
          System.runFinalization();
          System.gc();
         }
      }
   }

The problem I have is that when it has been working for several days the RAM memory is filled to the 1024 MB that I have indicated with VM Options -Xms 1024m. What indicates to me that the garbage collector does not eliminate the references of the variables, I have read that putting the variables used to null the garballe collector would eliminate the dead references, but I have a lot of internal variables. My question is if there is a different option so that it does not increase the size of the memory used in the application?

    
asked by F.Sola 04.05.2018 в 17:54
source

1 answer

2

If your application requires more and more memory over time, you have what is called a memory leak ( memory leak ).

It is not the number of variables, but the size in memory of each: 100 values Integer occupy almost nothing compared to a List<Integer> with 10000 elements. Check that you do not use global variables that store information unnecessarily (class attributes that are static ), for example.

    
answered by 04.05.2018 / 18:15
source