On Sun, Sep 09, 2012 at 02:09:45PM +0000, Benjamin Wang (gendwang) wrote: > Hi, > I wrote a code to verify the memory leak problem as following. > C code in so: > void checkJNAMemLeak1(int **head, int *length) > { > long i = 0; > > *head = (int *)malloc(sizeof(int) * 100000000); > for(i=0; i<100000000; i++) > { > (*head)[i] = 1; > } > > *length = 100000000; > } > > Java code: > public static void testJNAMemLeak1() > { > PointerByReference head = new PointerByReference(); > IntByReference length = new IntByReference(); > > while(true) > { > libben.checkJNAMemLeak1(head, length); > System.out.println(length.getValue()); > sleep(1); > > } > } > > When we check memory by top command, the virt and res will increase very quickly. When we check with jconsole, there is no memory in Java heap. Even I execute GC manually by jconsole. Nothing happen. > > If I change java code as following: > public static void testJNAMemLeak1() > { > PointerByReference head = new PointerByReference(); > IntByReference length = new IntByReference(); > > while(true) > { > libben.checkJNAMemLeak1(head, length); > System.out.println(length.getValue()); > sleep(1); > > libc.free(head.getValue()); > } > } > > public static void testJNAMemLeak1() > { > PointerByReference head = new PointerByReference(); > IntByReference length = new IntByReference(); > > while(true) > { > libben.checkJNAMemLeak1(head, length); > System.out.println(length.getValue()); > sleep(1); > > libc.free(head.getValue()); > } > } > > Then everything works well. The virt and res will not increase. > I think we must provide the free functions for all the memory allocated by libvirt. Okay, can you work on making a patch ? To be honnest I'm very unlikely to have time for this in the short term, Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@xxxxxxxxxxxx | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/ -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list