Boost Graph Library and Boehm Garbage Collector
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
(moving this to boost developer list) FBSL schrieb:
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.
you're right, the BGL uses the default new operator to allocate memory which then isn't collected of course. so this makes it effectively impossible to use BGL with boehm GC. is there a boost guideline to allocate memory only through allocators which is violated here? (the "new" which is causing the leak(or one of your leaks?) in your code is at line 278 of graph/detail/adjacency_list.hpp in version 1.32) -- Stefan Strasser
Thanks for answering. Stefan Strasser wrote:
you're right, the BGL uses the default new operator to allocate memory which then isn't collected of course. so this makes it effectively impossible to use BGL with boehm GC. is there a boost guideline to allocate memory only through allocators which is violated here? (the "new" which is causing the leak(or one of your leaks?) in your code is at line 278 of graph/detail/adjacency_list.hpp in version 1.32)
As a matter of facts, by modifying the snippet code and commenting out
the add_edge() instruction, the binary no longer leaks, so the guilty
"new" is certainly the one you point (which allocate for an edge
property). I tried to replace it by "new (UseGC)" in order to check if
edge properties become collectable, but unfortunately this does not
work, binary still leaks...
Snippet code is again provided.
--
#include
FBSL schrieb:
Thanks for answering.
Stefan Strasser wrote:
you're right, the BGL uses the default new operator to allocate memory which then isn't collected of course. so this makes it effectively impossible to use BGL with boehm GC. is there a boost guideline to allocate memory only through allocators which is violated here? (the "new" which is causing the leak(or one of your leaks?) in your code is at line 278 of graph/detail/adjacency_list.hpp in version 1.32)
As a matter of facts, by modifying the snippet code and commenting out the add_edge() instruction, the binary no longer leaks, so the guilty "new" is certainly the one you point (which allocate for an edge property). I tried to replace it by "new (UseGC)" in order to check if edge properties become collectable, but unfortunately this does not work, binary still leaks...
there are other new's in BGL, is another one used in your case? I've found the first one by simply stepping through it. I don't know if that's appropriate in your case but there is a way to replace the global new operator by boehm's collactable one, see homepage. though I still think BGL and boost in general shouldn't allocate memory without an user defined allocator, but there isn't much(read: none) interest in this on boost developer list. -- Stefan Strasser
Stefan Strasser wrote:
FBSL schrieb:
Thanks for answering.
Stefan Strasser wrote:
you're right, the BGL uses the default new operator to allocate memory which then isn't collected of course. so this makes it effectively impossible to use BGL with boehm GC. is there a boost guideline to allocate memory only through allocators which is violated here? (the "new" which is causing the leak(or one of your leaks?) in your code is at line 278 of graph/detail/adjacency_list.hpp in version 1.32)
As a matter of facts, by modifying the snippet code and commenting out the add_edge() instruction, the binary no longer leaks, so the guilty "new" is certainly the one you point (which allocate for an edge property). I tried to replace it by "new (UseGC)" in order to check if edge properties become collectable, but unfortunately this does not work, binary still leaks...
there are other new's in BGL, is another one used in your case? I've found the first one by simply stepping through it.
I don't know if that's appropriate in your case but there is a way to replace the global new operator by boehm's collactable one, see homepage. though I still think BGL and boost in general shouldn't allocate memory without an user defined allocator, but there isn't much(read: none) interest in this on boost developer list.
Hi. I'd like to add my support behind the ability to provide a custom allocator in the graph type definition. I'm writing an engine which will require relatively large (read: several GBs of RAM) graphs, so I think it pretty much a requirement that I be able to provide a custom allocator for pre-allocation of large segments of memory. That's all, thanks. Geoff
participants (3)
-
FBSL
-
Geoff Hilton
-
Stefan Strasser