Open abenkhadra opened 6 years ago
This can also be solved by just changing "const elf f" member of segment and section to "const elf& f". Because the elf keeps the children, they are alive as long as the parent is alive (obviously with this solution copies of segments and section must be in scope with the parent elf object).
object elf (parent) owns the memory of its children, namely, sections and segments. However, instances of the latter share memory ownership of the parent elf due to its pimpl implementation using shared_ptr. This creates a circular dependency that prevents cleaning the memory acquired by elf objects.
I break this circular dependency through the standard mechanism of weak_ptr. Basically, the children now own a weak_ptr to the implementation of their parent elf object. They instantiate an instance of the parent only when an action involving the parent is needed.