Hello
I am having trouble to garbage-collect adjacency_list<>. I have
instanciated it with correctly garbage-collected vectors and lists (I
have copied vecS and listS definitions, and added Boehm GC's default
allocator so that they are garbage-collected). In my application I need
to dynamically allocate many graphs, but it does not work, there is a
(big) memory leak. Unfortunately, there is no template argument in
adjacency_list<> to specify Boehm GC's allocator.
Does anyone have a hint ?
Snippet code "main.cpp" follows, compiled with Boost Graph Library 1.32,
Boehm GC 6.4 and G++ 3.3.5, with command line :
$ g++ -o main main.cpp -lgc -lgccpp
--
#include
#include
#include
#include <iostream>
#include <vector>
#include <list>
using namespace std;
using namespace boost;
namespace boost {
struct collected_vecS {};
struct collected_listS {};
template <class ValueType>
struct container_gen {
typedef vector type;
};
template <class ValueType>
struct container_gen {
typedef list type;
};
template <>
struct parallel_edge_traits {
typedef allow_parallel_edge_tag type; };
template <>
struct parallel_edge_traits {
typedef allow_parallel_edge_tag type; };
namespace detail {
template <>
struct is_random_access {
enum { value = true };
typedef true_type type;
};
}
}
typedef adjacency_list graph;
int
main()
{
// leaks...
while(true){
graph * g=new (UseGC) graph;
for(unsigned int i=0; i<100; ++i){
add_vertex(*g);
}
for(unsigned int i=0; i<100; ++i){
for(unsigned int j=0; j<100; ++j){
add_edge(i,j,*g);
}
}
}
}