Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Deletion of sfml objects  (Read 1335 times)

0 Members and 1 Guest are viewing this topic.

slohobo

  • Newbie
  • *
  • Posts: 5
    • View Profile
Deletion of sfml objects
« 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).

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Deletion of sfml objects
« Reply #1 on: August 27, 2017, 01:44:02 am »
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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything