SFML community forums
Help => General => Topic started by: slohobo on August 26, 2017, 05:41:36 pm
-
I have some objects that are taking up heap space on the memory by using the new operator and I want to know if I am properly deleting these objects. Whenever I allocate them onto heap the heap I delete them using the delete operator because I didn't see a deconstructor in any of the sfml classes (looking at the header files provided on the sfml site).
-
Custom destructors are not necessary when the default destructors will do the job required.
That is, they have implicit destructors and they are called whenever they are destroyed.
If you are using manual memory management with raw pointers and new to store SFML objects, yes, you can remove them with delete.
However, consider instead using smart pointers (std::unique_ptr<sf::Texture> texture; instead of sf::Texture* texture;, for example) as they're much safer (http://bromeon.ch/articles/raii.html).