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

Author Topic: [FIXED] sf::Image Deallocation? (future advise still liked)  (Read 1408 times)

0 Members and 1 Guest are viewing this topic.

ninjamint

  • Newbie
  • *
  • Posts: 15
    • View Profile
[FIXED] sf::Image Deallocation? (future advise still liked)
« on: December 19, 2009, 02:23:21 am »
I'm viewing 3D models, and when doing so, every-time I change the model, a memory leak appears cause the memory usage is increased dramatically, with every new model thats loaded(perhaps this is because the new model doesn't use the same texture as the previous, and some sort of caching prevents the old textures from being de-allocated). Though, if I disable the textures(or they fail to load) the memory barely changes(it still constantly increases... meaning I have another memory leak somewhere, but its such a small increase, that I am not worried about it). However the textures cause the memory usage to increase by 1,000+ kb/s; and that's a problem as I run out of virtual memory quick. So, my current method of de-allocating the sf::Image is like this..

Code: [Select]
for(unsigned int i = 0; i < f.tex_fns.size(); ++i)
delete &f.sfTextures[i];
f.sfTextures = 0;


where f.sfTextures is a sf::Image *;

any help would be greatly appreciated!

well, I stopped using sf::Image*, and switched to using a std::vector<sf::Image>, and that fixed the problem.. >.> but if you know what was wrong before, please let me know, for future situations, cause I don't like using std::vector all the time lol

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[FIXED] sf::Image Deallocation? (future advise still liked)
« Reply #1 on: December 19, 2009, 10:31:44 am »
It should be
Code: [Select]
delete[] f.sfTextures;

And yes, you should really use std::vector when you have a dynamic array ;)
Laurent Gomila - SFML developer

 

anything