From 6006790c18e6f9207cd0ec3c6129365c8bf5f1ea Mon Sep 17 00:00:00 2001 From: Andrey Pavlenko Date: Tue, 26 May 2015 13:10:54 +0300 Subject: [PATCH 1/2] releasing native memory in Java converters --- .../java/generator/src/java/utils+Converters.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/java/generator/src/java/utils+Converters.java b/modules/java/generator/src/java/utils+Converters.java index cd4fb9863a..bd3bb64927 100644 --- a/modules/java/generator/src/java/utils+Converters.java +++ b/modules/java/generator/src/java/utils+Converters.java @@ -501,7 +501,9 @@ public class Converters { for (Mat mi : mats) { MatOfPoint pt = new MatOfPoint(mi); pts.add(pt); + mi.release(); } + mats.clear(); } // vector_vector_Point2f @@ -517,7 +519,9 @@ public class Converters { for (Mat mi : mats) { MatOfPoint2f pt = new MatOfPoint2f(mi); pts.add(pt); + mi.release(); } + mats.clear(); } // vector_vector_Point2f @@ -547,7 +551,9 @@ public class Converters { for (Mat mi : mats) { MatOfPoint3f pt = new MatOfPoint3f(mi); pts.add(pt); + mi.release(); } + mats.clear(); } // vector_vector_Point3f @@ -590,7 +596,9 @@ public class Converters { for (Mat mi : mats) { MatOfKeyPoint vkp = new MatOfKeyPoint(mi); kps.add(vkp); + mi.release(); } + mats.clear(); } public static Mat vector_double_to_Mat(List ds) { @@ -689,7 +697,9 @@ public class Converters { for (Mat mi : mats) { MatOfDMatch vdm = new MatOfDMatch(mi); lvdm.add(vdm); + mi.release(); } + mats.clear(); } // vector_vector_char @@ -719,6 +729,8 @@ public class Converters { List lb = new ArrayList(); Mat_to_vector_char(mi, lb); llb.add(lb); + mi.release(); } + mats.clear(); } } From c1c03e16f4b77eca0c81def98f27703df2cba5fc Mon Sep 17 00:00:00 2001 From: Andrey Pavlenko Date: Tue, 26 May 2015 13:50:56 +0300 Subject: [PATCH 2/2] releasing native memory of temp `Mat` objects in generated Java code --- modules/java/generator/gen_java.py | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/java/generator/gen_java.py b/modules/java/generator/gen_java.py index b9fce4294b..22e42f0db5 100755 --- a/modules/java/generator/gen_java.py +++ b/modules/java/generator/gen_java.py @@ -1240,6 +1240,7 @@ class JavaWrapperGenerator(object): if "O" in a.out: if not type_dict[a.ctype]["j_type"].startswith("MatOf"): j_epilogue.append("Converters.Mat_to_%(t)s(%(n)s_mat, %(n)s);" % {"t" : a.ctype, "n" : a.name}) + j_epilogue.append( "%s_mat.release();" % a.name ) c_epilogue.append( "%(t)s_to_Mat( %(n)s, %(n)s_mat );" % {"n" : a.name, "t" : a.ctype} ) else: fields = type_dict[a.ctype].get("jn_args", ((a.ctype, ""),))