Memory Managment issues
Luke Petre <[email protected]> Thu, 25 Jan 2007 11:51:40 -0800
| Newsgroups | gmane.comp.documentation.synopsis |
|---|---|
| Message-ID | <[email protected]> |
Howdy all. I'm unfortunately unable to use the latest Synopsis release, but a quick browse of the head revision in SVN makes it seem like the problems I'm having are still around. There appears to be at least two memory management schemes used by Synopsis. Synopsis::SymbolTable::Scope uses a reference counting scheme. It severely leaks memory, as the SymbolFactory does not properly release references, nor does the walker, and every nested Scope creates a circular reference. This was a pretty straight forward fix, changing the code to have the outer scopes hold a reference to the inner scopes, and adding the proper refs and unrefs in the factory and walker. I hope I can make this change into a .patch file to submit back to the main branch. Secondly there are the objects in the Synopsis::PTree namespace which use the Boehm GC library. This appears to be based on the OpenC++ parser, so I believe it generally works w/ respect to memory management. The one place I do notice a difference is in the Encoding class. In the OpenC++ parser, that class has a character buffer with a fixed size. In the Synopsis implementation it uses a std::string. This causes problems because the std::string is ultimately owned by a garbage collected object, but is allocating memory from a non-garbage collected heap. My first attempt at fixing this was to use the gc_allocator, which is included in the boehm-gc library and implements a std::allocator. That was basically a simple change in Encoding.hh to this line: typedef std::basic_string<unsigned char, char_traits> Code; To become: typedef std::basic_string<unsigned char, char_traits, gc_allocator<unsigned char>> Code; And the addition of: #include <gc_allocator.h> also to Encoding.hh These two fixes appear to address the majority of memory leaks. Unfortunately when I parse one of our more complex headers, I seem to be sending the Boehm collector into an infinite loop. I'm tempted to re-re-implement the Encoding.hh object with either a fixed size buffer, or a dynamic buffer that I manage with 'new (PTree::GC) unsigned char[..]' calls (see Encoding::copy). Thoughts? Luke