Am I Leaking? STL + Texture Manager...

Started by
12 comments, last by GroZZleR 20 years, 4 months ago
quote:Original post by Enokh
I thought that if you have a vector in a class which is in static memory (ex: int x) then when that variable exists the scope the vector inside it will completely erase itself as well automatically. Don''t even need a deconstructor... Am I wrong here?


Do you mean that if you have a vector inside an object, and the object goes out of scope (destructs) then the vector will erase itself? If that''s what you meant, then yes.. the vector erases itself in its destructor.

daveandrews.org - a Christian Programmer''s Weblog | Dusty Engine - a task engine using Irrlicht | Computer Guys Run the World
How to be a Programmer
Advertisement
But I''m allocating memory itself inside the vector...

vector.pushback(new CObject);

So when the vector goes out of scope, the list of pointers is lost but the memory itself is not freed.
quote:Original post by krez
even if the pointer was NULL (0), you could still delete it (you don''t need the "if" much less the "assert"). if it wasn''t NULL, but pointed to an invalid address, neither would help anyway.

i''d check that the pointer wasn''t NULL or invalid before putting it in the vector.

eh, don''t mind me, i was just pointing it out in case someone else reading didn''t know. i guess it sounded like i was trying to press my style on you. i hope i didn''t come off as a dick.


You completely did not read, and/or comprehend, what he just said.

Yes, you CAN call delete on something that is NULL without issue, but, it should not ever be null, and if it is, he would like to know about it (error checking). If you just call delete without any type of checking, there is no way to know when something goes bad.
for managers (mesh or texture) i use an std::map, and smart pointers instead of pointers. So when i use the clear() method, smartpointer destructor takes care of memory deletion.
I think its a kinda good use of SPs. Opinions anyone?

This topic is closed to new replies.

Advertisement