Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] Memory leaks in CGAL

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] Memory leaks in CGAL


Chronological Thread 
  • From: Stzpz <>
  • To:
  • Subject: Re: [cgal-discuss] Memory leaks in CGAL
  • Date: Wed, 2 Mar 2011 12:23:52 +0800
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; b=uGsYSt+qwe/fwYd4yX/COg4RjbW9QuIutmig1kmRcpubDuNULU3dt/ikwwkmlk8lvC g+iuD9/oxA5nlTSLeP9iF8pwNTLPlUG1MTA1rjEQsPh03bdORNqX+SpdIZkDN1Sd5uia RAlVCbPcuopphB5TZNeIZRZcW0kH5DyPKjaRs=

Thanks so much for both patches and the advice. You are really amazing!

Stzpz


2011/3/1 Sebastien Loriot (GeometryFactory) <sloriot.ml@gmail.com>
stzpz wrote:
I am using Bezier Arrangement in CGAL, and found that there exist some memory
leak problems when I inserting bezier curves into the arrangement using
insert(). Here is the code and the data.

===================== CODE BEGIN ======================
#include <CGAL/basic.h>
#include <CGAL/Cartesian.h>
#include <CGAL/CORE_algebraic_number_traits.h>
#include <CGAL/Arr_Bezier_curve_traits_2.h>
#include <CGAL/Arrangement_2.h>
#include <list>
using namespace std;

typedef CGAL::CORE_algebraic_number_traits              Nt_traits;
typedef Nt_traits::Rational                             NT;
typedef Nt_traits::Rational                             Rational;
typedef Nt_traits::Algebraic                            Algebraic;
typedef CGAL::Cartesian<Rational>                       Rat_kernel;
typedef CGAL::Cartesian<Algebraic>                      Alg_kernel;
typedef Rat_kernel::Point_2                             Rat_point_2;
typedef CGAL::Arr_Bezier_curve_traits_2<Rat_kernel, Alg_kernel, Nt_traits>
Traits_2;
typedef Traits_2::Curve_2 Bezier_curve_2;
typedef CGAL::Arrangement_2<Traits_2>                   Arrangement_2;

void insertCurves(const char *filename, Arrangement_2 *arr)
{
   std::ifstream in_file (filename);

   int n_curves;
   list<Bezier_curve_2> curves;
   int k;
   Bezier_curve_2 B;
       in_file >> n_curves;
   for (k = 0; k < n_curves; k++) {
       in_file >> B;
       curves.push_back(B);
   }
   // Memory leaks here
   insert (*arr, curves.begin(), curves.end());
}

int main (int argc, char *argv[])
{
   const char *filename = (argc > 1) ? argv[1] : "test_data.txt";
   int k = 0;
   while(true)
   {
       Arrangement_2 arr;
       insertCurves(filename, &arr);
       printf("%d done.\n", k++);
   }
   return 0;
}
==================== CODE END ========================

==================== test_data.txt BEGIN ======================
3
4 -147 -99 102 -99 102 -99 102 -99 4 -116 -145 -56 41 -56 41 -56 41 4 -148 20 121 -159 121 -159 121 -159 ==================== test_data.txt END ========================

When I running this program, the using memory is increasing rapidly, which
can be seen from the Windows Task Manager. It seems that most of the memory
leaks was caused by the MemoryPool< T, nObjects >::allocate() in
CORE\MemoryPool.h, which is reported by Visual Leak Detector.

Does anyone know how to solve it? Or is there anyway to use other kinds of
Kernel like GMP instead of CORE?

Besides, I also found a bug that insert() will crash if the input curves are
identical, just like the test data below when using the code above:
=================== Test data BEGIN ===================
2
2 0 0 100 100
2 0 0 100 100
==================== Test data END ====================

Here is the patched file for identical Bezier curves.
Note that since you are using segments, it might be more efficient to
detect this before inserting segments in the arrangement.

S.

Thanks very much!

Stzpz





--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://lists-sop.inria.fr/wws/info/cgal-discuss





Archive powered by MHonArc 2.6.16.

Top of Page