tipforeveryone Posted June 3, 2019 Posted June 3, 2019 I have this code std::vector<Texture*> spriteSequences; for (int i = 1; i <= 20; i++) { Texture* texture = nullptr; texture = Texture::Load(folderPath + "/" + String(i) + ".tex"); spriteSequences.push_back(texture); } in Destructor of my class MyClass::~MyClass() { delete[] spriteSequences; //this is not working } How can I delete a vector of Pointer ? Quote
SpiderPig Posted June 3, 2019 Posted June 3, 2019 For(int id=0;id <spriteSequences.size ();id++) { SpriteSequences[id]->Release (); } SpriteSequence.clear () \\resets the list to 0 size Quote
tipforeveryone Posted June 3, 2019 Author Posted June 3, 2019 Thanks !! additional question, with vector.clear(), will the vector be wiped out from memory ? Quote
Josh Posted June 3, 2019 Posted June 3, 2019 3 hours ago, tipforeveryone said: Thanks !! additional question, with vector.clear(), will the vector be wiped out from memory ? clear() will not objects that have pointers stored in the vector. Internally, it will also not deallocate the vector memory, which makes this ideal for something you fill and empty over and over again. I believe resize() will actually allocate a new smaller block of memory. In the new engine, using shared pointers, clearing the vector would cause the contained objects to be deleted if they are not being used anywhere else. Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.