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

Author Topic: Memory released ..  (Read 3039 times)

0 Members and 1 Guest are viewing this topic.

HeinzK

  • Newbie
  • *
  • Posts: 41
    • View Profile
    • ZwiAner
    • Email
Memory released ..
« on: May 10, 2012, 01:37:41 pm »
deleted
« Last Edit: December 04, 2019, 08:27:50 am by HeinzK »
The trees, that obstruct the view on the forest, can be allowed to fall! (Die Bäume, die die Sicht auf einen Wald versperren, dürfen gefällt werden!)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Memory released ..
« Reply #1 on: May 10, 2012, 01:46:51 pm »
Sorry but I don't understand your question :-\

And do you really need all these dynamic allocations?
Laurent Gomila - SFML developer

HeinzK

  • Newbie
  • *
  • Posts: 41
    • View Profile
    • ZwiAner
    • Email
Re: Memory released ..
« Reply #2 on: May 10, 2012, 01:52:57 pm »
Yes, I need it for a std::vector<> array.
My questino: is it a memoryleak possible, when I do that?
The trees, that obstruct the view on the forest, can be allowed to fall! (Die Bäume, die die Sicht auf einen Wald versperren, dürfen gefällt werden!)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Memory released ..
« Reply #3 on: May 10, 2012, 01:55:13 pm »
Quote
Yes, I need it for a std::vector<> array.
std::vector already knows how to dynamically grow when you add elements, the elements themselves don't need to be dynamically allocated.

Quote
My questino: is it a memoryleak possible, when I do that?
Yes, everything that is allocated with new must be destroyed with delete. SFML never takes the ownership of user objects.
Laurent Gomila - SFML developer

Zefz

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Memory released ..
« Reply #4 on: May 11, 2012, 12:15:54 pm »
std::vector does not need to hold pointers.

std::vector<SoundBuffer> myVector;

//Load some sounds
myVector.resize(3);
myVector[0].loadFromFile("sound1.wav");
myVector[1].loadFromFile("sound2.wav");
myVector[2].loadFromFile("sound3.wav");

myVector.clear();  //all memory is freed! no memory leaks
 

HeinzK

  • Newbie
  • *
  • Posts: 41
    • View Profile
    • ZwiAner
    • Email
Re: Memory released ..
« Reply #5 on: May 15, 2012, 11:12:12 am »
OK, but I have different ranges.
At this moment all things are working by me.
Thank you for the tip.
The trees, that obstruct the view on the forest, can be allowed to fall! (Die Bäume, die die Sicht auf einen Wald versperren, dürfen gefällt werden!)

 

anything