Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] Memory leak in snap_rounding_2?

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] Memory leak in snap_rounding_2?


Chronological Thread 
  • From: Philipp Moeller <>
  • To: Steven <>
  • Cc:
  • Subject: Re: [cgal-discuss] Memory leak in snap_rounding_2?
  • Date: Wed, 30 Oct 2013 12:13:28 +0100
  • Organization: GeometryFactory

Steven
<>
writes:

> Thank you for your reply.
>
> While waiting for someone with more insight to provide a solid patch, is
> there any way I can try to temporarily patch it on my machine? I tried
> editing the code in the header files, but even though they seem to be
> compiled (i.e. I get compiler errors for silly mistakes), at runtime they
> don't seem to have any effect.
>
> (This is probably where my lack of c++ experience really shows...)

I forgot to attach the diff in the last message. Sorry for the noise.

diff --git a/Snap_rounding_2/include/CGAL/Snap_rounding_2.h b/Snap_rounding_2/include/CGAL/Snap_rounding_2.h
index 05edac9..5bbac9a 100644
--- a/Snap_rounding_2/include/CGAL/Snap_rounding_2.h
+++ b/Snap_rounding_2/include/CGAL/Snap_rounding_2.h
@@ -287,10 +287,10 @@ Hot_pixel<Traits_>::Hot_pixel(const Point_2 & inp_point, NT inp_pixel_size) :
 template<class Traits_>
 Hot_pixel<Traits_>::~Hot_pixel()
 {
-  delete(right_seg);
-  delete(left_seg);
-  delete(top_seg);
-  delete(bot_seg);
+  delete right_seg;
+  delete left_seg;
+  delete top_seg;
+  delete bot_seg;
 }
 
 /*! */
@@ -714,7 +714,7 @@ iterate(OutputContainer & output_container,
       // segment entirely inside a pixel
       hp = new Hot_pixel(iter->source(), pixel_size);
       seg_output.push_back(hp->get_center(int_output));
-      delete(hp);
+      delete hp;
     } else {
       seg_output.push_back((*hot_pixel_iter)->get_center(int_output));
       if (number_of_intersections > 1) {
@@ -769,6 +769,10 @@ void snap_rounding_2(InputIterator begin,
   s.iterate(output_container, pixel_size, int_output, do_isr,seg_list,
             mul_kd_tree);
 
+  // hope that find_hot_pixels_and_create_kd_trees does not suddenly
+  // new up an array of multiple kd_tree
+  delete mul_kd_tree;
+
 #ifdef CGAL_SR_DEBUG
   std::cout << "Overall number of false hot pixels in all the queries : "
             << number_of_false_hp << std::endl;
	Modified   Snap_rounding_2/include/CGAL/Snap_rounding_kd_2.h
diff --git a/Snap_rounding_2/include/CGAL/Snap_rounding_kd_2.h b/Snap_rounding_2/include/CGAL/Snap_rounding_kd_2.h
index de738a4..1000856 100644
--- a/Snap_rounding_2/include/CGAL/Snap_rounding_kd_2.h
+++ b/Snap_rounding_2/include/CGAL/Snap_rounding_kd_2.h
@@ -27,6 +27,9 @@
 #include <iostream>
 #include <CGAL/predicates_on_points_2.h>
 #include <CGAL/utility.h>
+#include <CGAL/assertions.h>
+
+#include <boost/type_traits/is_pointer.hpp>
 
 namespace CGAL {
 
@@ -48,6 +51,7 @@ public:
 
 template<class Traits_, class SAVED_OBJECT>
 class Multiple_kd_tree {
+  CGAL_static_assertion_msg((boost::is_pointer<SAVED_OBJECT>::value), "SAVED_OBJECT is not a pointer.");
 private:
   typedef Traits_                                       Traits;
   typedef typename Traits::FT                           NT;
@@ -384,6 +388,8 @@ public:
       ++ind;
     }
 
+    delete[] kd_counter;
+
 #ifdef CGAL_SR_DEBUG
     std::cout << "Actual number of kd-trees created : " <<
       number_of_actual_kd_trees << std::endl;
@@ -391,6 +397,19 @@ public:
 
   }
 
+  ~Multiple_kd_tree() {
+    for(typename Kd_triple_list::iterator it = kd_trees_list.begin(); 
+        it != kd_trees_list.end(); ++it) { 
+      delete (it->first);
+    }
+
+    for(typename Point_saved_pair_list::iterator it = input_points_list.begin(); 
+        it != input_points_list.end(); ++it) { 
+      delete (it->second);
+    }
+
+  }
+
   /*! */
   Point_2 small_x_point(const Point_2 & p1, const Point_2 & p2)
   {




Archive powered by MHonArc 2.6.18.

Top of Page