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

Author Topic: Do you have to delete created objects?  (Read 2155 times)

0 Members and 1 Guest are viewing this topic.

Iglosen

  • Newbie
  • *
  • Posts: 5
    • View Profile
Do you have to delete created objects?
« on: January 05, 2018, 09:02:16 am »
Hello!
I have been developing a game these last 2 months and it's starting to take form.
This is a school project and I'm not allowed to have memory leaks on this project.
So, I include the CRT library to detect memory leaks, and there is a ton of them. I have no clue where these are coming from so my first thought was if I have to delete all my Sprites/Textures/Fonts/Shapes and etc. manually as well when the game closes down.
Is this true?

Keep in mind I'm not talking about Sprites/Textures/Fonts/Shapes as a pointer, but as an object.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Do you have to delete created objects?
« Reply #1 on: January 05, 2018, 09:25:06 am »
You don't have to do anything special. Just care about the memory that you allocate yourself.

Can you post the log of the leak detection tool?
Laurent Gomila - SFML developer

Iglosen

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Do you have to delete created objects?
« Reply #2 on: January 05, 2018, 10:22:02 am »
.-.-
« Last Edit: January 05, 2018, 09:51:10 pm by Iglosen »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Do you have to delete created objects?
« Reply #3 on: January 05, 2018, 10:39:42 am »
Aren't there options to show more useful information?

Also, don't forget that this CRT report is not 100% accurate; especially since SFML has some global variables that may get freed after the tool stops its analysis.
Laurent Gomila - SFML developer

Iglosen

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Do you have to delete created objects?
« Reply #4 on: January 05, 2018, 10:49:47 am »
There should be an option to see at what line and from what file the memory gets allocated, but it doesn't seem to work for me :(

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Do you have to delete created objects?
« Reply #5 on: January 05, 2018, 11:58:15 am »
Are you running your program in debug mode?
Laurent Gomila - SFML developer

Iglosen

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Do you have to delete created objects?
« Reply #6 on: January 05, 2018, 12:38:08 pm »
.-.-
« Last Edit: January 05, 2018, 09:50:24 pm by Iglosen »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Do you have to delete created objects?
« Reply #7 on: January 05, 2018, 12:40:40 pm »
Dumping leaks at the end of main() is definitely not going to give relevant results, because of globals. You should rather use a dedicated (external) tool to check for leaks.
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10883
    • View Profile
    • development blog
    • Email
Re: Do you have to delete created objects?
« Reply #8 on: January 05, 2018, 12:45:10 pm »
I also urge you to talk to your teacher/assistant. If they make the requirement of zero memory leak, they should also provide the necessary tools and knowledge base to ensure such a requirement.

And keep in mind that using memory leak tools isn't always that trivial and understanding the results and being able to differentiate between false-positive and actual leaks requires some further understanding.
« Last Edit: January 05, 2018, 03:02:42 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Iglosen

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Do you have to delete created objects?
« Reply #9 on: January 05, 2018, 01:28:06 pm »
@Laurent
Are you talking about external plugins like visual leak detector etc.?

@eXpl0it3r
Yeah, that's a valid point.
I'll send her a DM =)

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Do you have to delete created objects?
« Reply #10 on: January 05, 2018, 04:46:17 pm »
If I were in your situation, I would just set up a VirtualBox machine running Linux and build the game using clang and -fsanitize=memory. Even building with GCC and using valgrind should be good enough for your purposes. Performance isn't relevant when making sure your code is clean so even software emulated graphics will work.

Believe it or not, it is actually easier to go this route than try to get usable (and reliable) leak detection working on Windows. There are enough tutorials on the internet regarding valgrind and the clang sanitizers. The added bonus with clang is that you can just as easily detect any of the much nastier errors in your game as well. Leaks are only the tip of the iceberg.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

 

anything