-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[common/point_cloud] Please re-add virtual destructor to PointCloud for safe inheritance #4036
Comments
If you know of a place where we manage the memory manually, we cant try to rectify that. |
Sorry for the delayed response. You have far more experience in how the codebase is structured and maintained than I do. I just know that I was recently burned by a non-virtual destructor inheritance case and so am therefore a bit "on edge" about such matters. For the purposes of the code that I / my team are writing, it certainly works best for us to inherit from pcl::PointCloud and extend functionality than to rely on composition or other methods that we have previously tried. So, avoiding slicing and memory leaks while still maintaining the ability to reuse the majority of PCL functions with our inherited cloud type is of great importance to us. By inheriting, we are mainly attempting to handle various LiDAR devices and managing their intrinsic information alongside the PointCloud that they generated. There is some provision for this in the "header" field of a standard PointCloud, but not enough to be useful to us. Most functions I have seen do in fact take an object that was created externally (not managed by the PCL library) and either use it without changing it (const ref, const pointer, etc.) or use it to build up another object which is then handed back off (again not managed by the PCL library code). If you are fairly certain that not having a virtual destructor should not cause issues moving forward with a "custom point cloud" which inherits from pcl::PointCloud then that would be satisfactory consolation for now. Thank you for your feedback on this! |
I think so. I'd reiterate again: If you find a place where our removal of virtual dtor causes issues, please bring the matter to our notice and we'd try to rectify it first without using virtual dtor, then by using a virtual dtor.
This is quite relatable. But the fact remains: Virtual dtor make all users pay a cost which we'd like to avoid, as long as possible. 😄 Closing the issue (🤞) |
Aroze from discussion in PointCloudLibrary#4036
Aroze from discussion in PointCloudLibrary#4036
My colleague and I recently attempted to update to PCL 1.10.1 [skipping 1.10.0] and noticed that in this commit from Nov. 2019 the "default destructors" were removed.
I see from this discussion on the pull request that certain virtual destructors were removed because PCL did not leverage them internally.
It is this one specifically that concerns me.
My concern: If the virtual destructor is removed, and I am inheriting from PointCloud (for reasons unspecified here, but available upon request) does this not open my code up to memory leaks if I pass my DerivedCloud into an existing PCL function which takes a PointCloud and then calls something that deletes the PointCloud downcast version of my DerivedCloud?
If it is not hurting anything to leave the virtual destructor for PointCloud (or in this case re-add the virtual destructor) can the virtual destructor be re-added so that I can continue to "safely inherit" from PointCloud?
The text was updated successfully, but these errors were encountered: