Conversation
| unloadLibraryInternal(false); | ||
| } | ||
| if (remove_when_possible) { | ||
| delete this; |
There was a problem hiding this comment.
@ahcorde this is very unusual. I'd suggest we use an std::shared_ptr to track ClassLoader ownership and defer cleanup tasks to its destructor.
| template<class Base> | ||
| Base * createUnmanagedInstance(const std::string & derived_class_name) | ||
| { | ||
| class_loader_ref_count--; |
There was a problem hiding this comment.
@ahcorde to compensate for the ref count increase in createRawInstance? What if a plugin is simultaneously deleted? I'd strongly suggest not creating these glitches in the ref count.
| ", keeping library %s open.", | ||
| library_path.c_str()); | ||
| } | ||
| purgeGraveyardOfMetaobjects(library_path, loader, true); |
There was a problem hiding this comment.
@ahcorde hmm, I think this was not here on purpose:
class_loader/src/class_loader_core.cpp
Lines 235 to 242 in 7b03fe3
But I wonder why
class_loader/test/unique_ptr_test.cpp
Line 174 in 471c398
Signed-off-by: ahcorde <ahcorde@gmail.com>
Signed-off-by: ahcorde <ahcorde@gmail.com>
Signed-off-by: ahcorde <ahcorde@gmail.com>
Signed-off-by: ahcorde <ahcorde@gmail.com>
Signed-off-by: ahcorde <ahcorde@gmail.com>
563ef2b to
6ced46e
Compare
hidmic
left a comment
There was a problem hiding this comment.
Once comments are addressed and CI goes green, I'm onboard with the change.
Signed-off-by: ahcorde <ahcorde@gmail.com>
hidmic
left a comment
There was a problem hiding this comment.
uncrustify is angry again
Signed-off-by: ahcorde <ahcorde@gmail.com>
| * This class inherit from enable_shared_from_this which means we must used smart pointers, | ||
| * otherwise the code might work but it may run into a leak. |
There was a problem hiding this comment.
@ahcorde nit:
| * This class inherit from enable_shared_from_this which means we must used smart pointers, | |
| * otherwise the code might work but it may run into a leak. | |
| * This class inherits from `std::enable_shared_from_this`. It should be instantiated using an `std::shared_ptr`. | |
| * Code will otherwise work but memory may be leaked. |
| ", keeping library %s open.", | ||
| library_path.c_str()); | ||
| } | ||
| purgeGraveyardOfMetaobjects(library_path, loader, true); |
| for (unsigned int i = 0; i < impl_->associated_class_loaders_.size(); i++) { | ||
| delete impl_->associated_class_loaders_[i]; | ||
| } |
There was a problem hiding this comment.
I don't understand how this doesn't cause problems unless these AbstractMetaObjectBase are never destroyed while the program is running?
Are these not the same ClassLoaders you are storing in shared_ptr objects?
Signed-off-by: ahcorde ahcorde@gmail.com
I ran class_loader with asan and I found some memory leaks.
There is still one memory leak when we create unmanaged instance, the way to reproduce this leak is to run
basicLoadUnmanagedandnoWarningOnLazyLoadtests at the same time.what is the right way to destroy this memory ?