Memory leak using toFormat(String) API call?

User c0e481a82c

06-12-2006 13:59:16

Is there an issue with using toFormat("mrv") in large datasets? What I'm finding is if I use:





toFormat("mol");





when looping over several thousand Molecule objects (about 7000), I can do this, where as if I do





toFormat("mrv");





over the same number, the memory usage grows and grows to the point where my machine runs out of memory. The ONLY line I'm changing is that one as detailed above. Could you tell me if there's a problem using toFormat("mrv") over such a number of molecules?





Regards,





Phil.

ChemAxon 7c2d26e5cf

07-12-2006 16:50:32

We have not found any problem with Molecule.toFormat("mrv").


I've created a simple example to test memory usage of toFormat. I've checked it with huge SD files (25000 compounds) but I had not found any dramatic / continuos memory increasing that would indicate a memory leak.


Would you test your compounds with this example? Have you got a memory problem with it?


Code:
import chemaxon.formats.*;


import chemaxon.struc.*;


import java.io.*;





/**


 * Simple molecule file converter.


 */


public class ToFormat


{


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


   if(args.length < 2) {


       System.out.println(


      "Usage: ToFormat input_file format\n"+


      "Example: ToFormat large.sdf mrv");


       System.exit(0);


   }


   MolImporter importer = new MolImporter(args[0]);


        String format = args[1];       


        Molecule mol = null;


        for(int i=0; (mol = importer.read()) != null;i++) {


       if(mol.getDim() == 0) {


           mol.clean(2, "O1");


       }


       String data = mol.toFormat(format);


            System.err.println("#"+(i+1));


            // print memory usage


            long total = Runtime.getRuntime().totalMemory();


            long free = Runtime.getRuntime().freeMemory();


            StringBuffer sb = new StringBuffer("Memory: ");


            java.text.DecimalFormat fmt = new java.text.DecimalFormat("0.0");


            sb.append(fmt.format(total/1048576.0));


            sb.append("MB total\t");


            sb.append(fmt.format((total - free)/1048576.0));


            sb.append("MB used");


            System.err.println(sb.toString());


        }


    }


}