Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6638459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:26:17+00:00 2026-05-25T23:26:17+00:00

What happens if I clear a vector which was already cleared before? I tried

  • 0

What happens if I clear a vector which was already cleared before?
I tried it out in Visual Studio and it did not lead to any run-time errors. But I’m hunting for a possible cause to an exception (below) And wanted to know if this could be the reason?

*** glibc detected *** process.out: double free or corruption (out): 0x01a0b588 *** 

Updating code:

bool myclass::Sort(SortType enSortOption)
{

  bool bRet = TRUE;


  m_oVecOfIntsOrig.clear();
  m_oVecOfIntsSorted.clear();

  for(int i = 0;i<m_oList.listsize();i++)
  {
    m_oVecOfIntsOrig.push_back(i);
  }
  m_oVecOfIntsSorted = m_oVecOfIntsOrig; 
  //Just sort the indices     
  switch(enSortOption)
  {
  case Alpha:
    { 
      t_SortStructAlpha sSortAlpha(this);
      sort( m_oVecOfIntsSorted.begin(), m_oVecOfIntsSorted.end(), sSortAlpha );        
    }
    break;
  case Dist:
    {        
      t_SortStructDist sSortDist(this);
      sort( m_oVecOfIntsSorted.begin(), m_oVecOfIntsSorted.end(), sSortDist );
    }
    break;
  case none:  
    {

      //Nothing to do
      return TRUE;
    }
    break;  
  default:
    {
      bRet = FALSE;

    }
    break;
  }

  //Update the list based on sorted index vector
  ListElem oSortedListElements;
  //this clear function simply clears all the 7 constituent vectors. 
  oSortedListElements.vClear();
  if(TRUE == bGetSortedList(oSortedListElements))
  {
    //If successfully copied to temp object, then update member variable
    //m_oList is what I'm intending to display
    m_oList.vClear();
    m_oList = oSortedListElements;
  }
  else
  {
    //copy failed
    bRet = FALSE;

  }
  return bRet;
}


bool myclass::bGetSortedList(ListElem& oSortedListElements)
{

  bool bRet = TRUE;

  //Creating object from beginning, so clear old contents if any
  oSortedListElements.vClear();
  /* Sort done. Now update the list based on new indices*/
  for(int u16Index = 0; u16Index<m_oVecOfIntsSorted.size(); u16Index++)
  {
    if(
      (m_oVecOfIntsSorted.at(u16Index) >= m_oListConstituents.oVec1.size())
      ||
      (m_oVecOfIntsSorted.at(u16Index) >= m_oListConstituents.oVec2.size())
      ||
      (m_oVecOfIntsSorted.at(u16Index) >= m_oListConstituents.oVec3.size())
      ||
      (m_oVecOfIntsSorted.at(u16Index) >= m_oListConstituents.oVec4.size())
      ||
      (m_oVecOfIntsSorted.at(u16Index) >= m_oListConstituents.oVec5.size())
      ||
      (m_oVecOfIntsSorted.at(u16Index) >= m_oListConstituents.oVec6.size())
      ||
      (m_oVecOfIntsSorted.at(u16Index) >= m_oListConstituents.oVec7.size())
      )
    {
      //out of bounds check
      return FALSE;
    }
    //m_oListConstituents contains overall list
    oSortedListElements.oVec1.push_back(m_oListConstituents.oVec1.at(m_oVecOfIntsSorted.at(u16Index)));
    oSortedListElements.oVec2.push_back(m_oListConstituents.oVec2.at(m_oVecOfIntsSorted.at(u16Index)));
    oSortedListElements.oVec3.push_back(m_oListConstituents.oVec3.at(m_oVecOfIntsSorted.at(u16Index)));
    oSortedListElements.oVec4.push_back(m_oListConstituents.oVec4.at(m_oVecOfIntsSorted.at(u16Index)));
    oSortedListElements.oVec5.push_back(m_oListConstituents.oVec5.at(m_oVecOfIntsSorted.at(u16Index)));
    oSortedListElements.oVec6.push_back(m_oListConstituents.oVec6.at(m_oVecOfIntsSorted.at(u16Index)));
    oSortedListElements.oVec7.push_back(m_oListConstituents.oVec7.at(m_oVecOfIntsSorted.at(u16Index)));     

  }

  return bRet;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:26:18+00:00Added an answer on May 25, 2026 at 11:26 pm

    Calling the clear method twice in a row should be fine. Your error looks like you are freeing something which was already freed. This can happen because you called free twice on the same object or possibly put an object in your vector which was then deleted. Calling clear on your vector would then cause that error (this is a problem because clear calls the destructor on any objects contained in the vector).

    Edit:

    at returns a reference so deleting something set to a value returned from an at might cause problems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm clear on the usage of MemoryBarrier, but not on what happens behind the
The Java documentation is not clear on this point. What happens if you call
I have searched and not found any clear answers to a problem im having.
I have tried this: g.RotateTransform(degrees); But nothing happens.I have one graphics object and one
This problem is probably very simple to solve but it is not clear to
First of all, im finding the iPhone online docs to be not-so-very thoroughly clear
I guess the question in the title is clear enough.What happens when i call
I'm still not very clear about the way cascade works in deletion operations. I
I am not clear on the mechanics of native interop. Suppose I do the
I just started doing my first Android app which happens to be an RSS

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.