If you're sure that the library won't require the abject later on, deleting it is fine.
You could also use smart pointers...which will automatically destroy it when not needed.
If you're sure that the library won't require the abject later on, deleting it is fine.
You could also use smart pointers...which will automatically destroy it when not needed.
I just found out experimentally that if I try to delete it just before I leave the function, I get a segmentation fault. This fault happens after the last line of the function and before the first line the main after calling the function. It seems that I cannot delete it without problems but that would seem to contradict what i have read about dynamically allocated memory and deleting.
@manasij7479 What is a smart pointer? How would you implement one?
That just means that it is needed afterwards.
I've never implemented one...but a popular way is using reference counting.(Google the term)@manasij7479 What is a smart pointer? How would you implement one?
But unless you're sure that you can do better, stick with the ones provided by the C++ standard.
Smart pointer - Wikipedia, the free encyclopedia