|
Boost Users : |
From: Martin Okrslar (okrslar_at_[hidden])
Date: 2003-04-30 06:37:29
Dear Boost users,
is the BGL leaky? For example the code added below produces memory leaks
(as seen from also added valgrind output).
When I comment out the line marked by /* THIS LINE DOES IT */, there are
no leaks. I am running BGL 1.29 and gcc 3.2.
Any ideas for a work-around?
cheers
Martin
#include <iostream> // for std::cout
#include <utility> // for std::pair
#include <algorithm> // for std::for_each
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
using namespace boost;
int main(int,char*[])
{
// create a typedef for the Graph type
typedef adjacency_list<vecS, vecS, bidirectionalS> Graph;
// Make convenient labels for the vertices
enum { A, B, C, D, E, N };
const int num_vertices = N;
// writing out the edges in the graph
typedef std::pair<int, int> Edge;
Edge edge_array[] =
{ Edge(A,B), Edge(A,D), Edge(C,A), Edge(D,C),
Edge(C,E), Edge(B,D), Edge(D,E), };
int num_edges = sizeof(edge_array)/sizeof(edge_array[0]);
// declare a graph object
Graph* g = new Graph(num_vertices);
// add the edges to the graph object
for (int i = 0; i < num_edges; ++i)
add_edge(edge_array[i].first, edge_array[i].second, *g); /* THIS
LINE DOES IT */
delete g;
return 0;
}
okrslar_at_liebrich:~/molgen/domclust/src/test> valgrind --leak-check=yes
--show-reachable=yes ./domclust
==23473== valgrind-1.0.4, a memory error detector for x86 GNU/Linux.
==23473== Copyright (C) 2000-2002, and GNU GPL'd, by Julian Seward.
==23473== Estimated CPU clock rate is 2412 MHz
==23473== For more details, rerun with: -v
==23473==
==23473==
==23473== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==23473== malloc/free: in use at exit: 384 bytes in 1 blocks.
==23473== malloc/free: 3 allocs, 2 frees, 544 bytes allocated.
==23473== For counts of detected errors, rerun with: -v
==23473== searching for pointers to 1 not-freed blocks.
==23473== checked 6470036 bytes.
==23473==
==23473== definitely lost: 0 bytes in 0 blocks.
==23473== possibly lost: 0 bytes in 0 blocks.
==23473== still reachable: 384 bytes in 1 blocks.
==23473==
==23473== 384 bytes in 1 blocks are still reachable in loss record 1 of 1
==23473== at 0x4004A3A8: __builtin_new (vg_clientfuncs.c:125)
==23473== by 0x4004A3F6: operator new(unsigned) (vg_clientfuncs.c:138)
==23473== by 0x4035E4F1: ??? (bits/stl_alloc.h:482)
==23473== by 0x4035E40D: ??? (bits/stl_alloc.h:532)
==23473==
==23473== LEAK SUMMARY:
==23473== definitely lost: 0 bytes in 0 blocks.
==23473== possibly lost: 0 bytes in 0 blocks.
==23473== still reachable: 384 bytes in 1 blocks.
==23473==
-- ----------------------------------------------------------------------------- Martin Okrslar MPI for Molecular Genetics phone: ++ 49 + 30 / 8413-1166 Computational Molecular Biology Fax: ++ 49 + 30 / 8413-1152 Ihnestrasse 73 email: okrslar_at_[hidden] D-14195 Berlin URL: http://cmb.molgen.mpg.de -----------------------------------------------------------------------------
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net