Jump to content

How can I delete a vector of Pointer ?


tipforeveryone
 Share

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 ?

Link to comment
Share on other sites

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.

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

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.

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.

 Share

×
×
  • Create New...