Jump to content
tipforeveryone

How can I delete a vector of Pointer ?

Recommended Posts

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 ?

Share this post


Link to post
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.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...