tipforeveryone Posted June 3, 2019 Share 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 Link to comment Share on other sites More sharing options...
SpiderPig Posted June 3, 2019 Share Posted June 3, 2019 For(int id=0;id <spriteSequences.size ();id++) { SpriteSequences[id]->Release (); } SpriteSequence.clear () \\resets the list to 0 size Quote Link to comment Share on other sites More sharing options...
tipforeveryone Posted June 3, 2019 Author Share Posted June 3, 2019 Thanks !! additional question, with vector.clear(), will the vector be wiped out from memory ? Quote Link to comment Share on other sites More sharing options...
Josh Posted June 3, 2019 Share 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. Link to comment Share on other sites More sharing options...
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.