How do you check memory for multiple algorithms?
Posted by: Phú Võ Lê Thanh
Date: February 14, 2022 01:48AM

Hi there researchers and developer,

I'm writing my first paper on novel data-mining algorithms, but I have this problem with checking memory.

I use SPMF's MemoryLogger, my code is something like:

algo1.run();
algo1.printStats();

algo2.run();
algo2.printStats();

algo3.run();
algo3.printStats();


I would like to check the three algo's memory at once, but it seems that the memory just adds up for some reasons, for example if i run above code I have something like this:

algo1.memory = 126 mb
algo2.memory = 327 mb
algo3.memory = 613 mb


Then if I run each algorithm separately one by one I have this:

algo1.memory = 127 mb
algo2.memory = 168 mb
algo3.memory = 13 mb


What causes this difference? And how do I fix it?
Thanks in advance.

Re: How do you check memory for multiple algorithms?
Date: February 16, 2022 03:42AM

Good evening,

The reason is that Java is an interpreted language and it uses the Garbage collector to free memory.

Basically, there is no guarantee when the Java Garbage Collector will free the memory. But in general, the Garbage Collector will just free memory when there is no more memory available. So this is the reason why the memory just add up... It means the GC did not clean the memory yet.

There is no way to force the GC to free memory in Java. Previously there was a command GC.clear() or something like that. But since many years, this command is deprecated and does not work.

The solution is to run the Java program several times. If you want to automatize this, you could create a batch file (.BAT file) and put the command to run the algorithm multiple times in that file and write a little bit code to save the memory and time results to a file. That would be a good solution.

Best regards,

Re: How do you check memory for multiple algorithms?
Posted by: Laticia
Date: March 06, 2022 05:15PM

Is it different to check memory on Linux and WIndows system?

Re: How do you check memory for multiple algorithms?
Date: March 07, 2022 04:29PM

Hi,

From a Java perspective, the programs run in a Java virtual machine that should have more or less the same behavior on different operating systems. ut it is not guaranteed.

Regards,

This forum is powered by Phorum and provided by P. Fournier-Viger (© 2012).
Terms of use.