@AlexAUT
Well, I basically already said everything of importance;
i have the class planet_system:
class planet_system
{
public:
planet_system(int intype, sf::Texture & texture_asteroid);
void Render(sf::RenderWindow &window, sf::RenderTexture & rtex, int centerviewx, int centerviewy, sf::Vector2f viewsize, sf::Texture tex);
void RenderParalax(sf::RenderWindow &window, sf::RenderTexture & rtex, int centerviewx, int centerviewy);
void Update();
void UpdatePriceMarket();
std::vector <cplanet> vecplanets;
int anzahl_planets;
std::vector <casteroidfield> vecasteroidfields;
sf::Texture tex_back;
sf::Sprite spr_back;
sf::Texture tex_paralax1;
sf::Sprite spr_paralax1;
sf::Texture tex_paralax2;
sf::Sprite spr_paralax2;
float sizex;
float sizey;
int type;
int id;
std::string string_name;
};
and have this in the delceration of main:
std::vector <planet_system> vecplanetsystems;
and in the game loop i have this when the new level is loaded:
// Either this
vecplanetsystems = std::vector <planet_system> ();
//or this ( but both dont work)
vecplanetsystems.clear();
vecplanetsystems.shrink_to_fit();
planet_system newsystem1(system_crnt, texmngr.getRef("asteroid1"));
vecplanetsystems.push_back(newsystem1);
And the Memory just won't be freed.
(!) But even when I just have a simple main with a vector of integers, fill and clear it, it is the same problem.
@Satus
It is not much more than this:
#include <iostream>
int main()
{
std::vector <int> vector;
for (long int i = 0; i < 800000; i++)
{
vector.push_back(12);
}
int cinbuffer;
std::cin >> cinbuffer;
vector.clear();
std::cin >> cinbuffer;
return 0;
}
(!) Although I just realised that it actually does free the memory when I also do
vector.shrink_to_fit();
But It doesn't work the same way in my game when I do the same thing, so my question is, if there are maybe problems with the textures inside planet_system etc which are not being freed.
Well, there is the class asteroid in the class planet_system. asteroid had this to handle the texture:
class asteroid(sf::Texture & tex_asteroid)
{
sf::Texture &texref = sf::Texture();
//...
}
and this was in the Constructor of asteroid:
texref = tex_asteroid;
I don't know exactly why these pointers caused this kind of problem, but I changed it so that there were no texture opjects or pointers anymore in asteroid and my memory problem disappeared ;D
Because the asteroids were stored in an vector inside of planet_system, I could guesss, that maybe the clearing and shrin_to_fit-ing of the planet_system-vector did not affect the asteroid-vector inside it?
Well, there is the class asteroid in the class planet_system. asteroid had this to handle the texture:
class asteroid(sf::Texture & tex_asteroid)
{
sf::Texture &texref = sf::Texture();
//...
}
That's not even remotely valid C++. That's exactly the problem Jesper mentioned: if you don't bother to describe exactly what you did, we have to make assumptions and guess.
So please come up with real code. If your original code is big, reduce it -- but make sure it's valid C++, complete and still reproduces your problem.
I don't know exactly why these pointers caused this kind of problem
I don't see a single pointer in your code. Again, express yourself clearly, to avoid being misunderstood.