Subject: CGAL users discussion list
List archive
- From: stzpz <>
- To:
- Subject: [cgal-discuss] Memory leaks in CGAL
- Date: Mon, 28 Feb 2011 01:50:28 -0800 (PST)
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 ====================
Thanks very much!
Stzpz
--
View this message in context:
http://cgal-discuss.949826.n4.nabble.com/Memory-leaks-in-CGAL-tp3327688p3327688.html
Sent from the cgal-discuss mailing list archive at Nabble.com.
- [cgal-discuss] Memory leaks in CGAL, stzpz, 02/28/2011
Archive powered by MHonArc 2.6.16.