|
Boost Users : |
From: FBSL (fbsl_at_[hidden])
Date: 2005-04-23 10:43:42
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 <boost/graph/adjacency_list.hpp> #include <gc/gc_allocator.h> #include <gc/gc_cpp.h> #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<collected_vecS, ValueType> { typedef vector<ValueType,gc_allocator<ValueType> > type; }; template <class ValueType> struct container_gen<collected_listS, ValueType> { typedef list<ValueType,gc_allocator<ValueType> > type; }; template <> struct parallel_edge_traits<collected_vecS> { typedef allow_parallel_edge_tag type; }; template <> struct parallel_edge_traits<collected_listS> { typedef allow_parallel_edge_tag type; }; namespace detail { template <> struct is_random_access<collected_vecS> { enum { value = true }; typedef true_type type; }; } } typedef adjacency_list<collected_vecS, collected_vecS, directedS, no_property, no_property, no_property, collected_listS> 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); } } } }
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