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

  • Home
  • SEARCH
  • 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 6736697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:09:38+00:00 2026-05-26T11:09:38+00:00

I have query regarding std::map. if I have a std::map like: std::map <T1, T2*>

  • 0

I have query regarding std::map.

if I have a std::map like:

std::map <T1, T2*> my_map;
T1 t;
T2* tt = new T2;
my_map[t]=tt;

who is responsible to clean this container, Will destructor of T2 will take care of it (T2* tt). Also if I want to retain this container throughout the program, where should I clean it.

Thanks

  • 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-26T11:09:39+00:00Added an answer on May 26, 2026 at 11:09 am

    The map destroys the objects stored in the map. The map stores some T1 objects, which will be destroyed, and it stores some T2 pointers, which will be destroyed.

    But it does not store actual T2 objects. So no T2 objects will be destroyed.

    Raw pointers do not have ownership of the objects they point to. So when a pointer is destroyed, it will not delete whatever it points to.

    Generally speaking, when you have a pointer, there is no way to know if

    • it points to a valid object at all (you don’t want to call delete on some random garbage in memory),
    • the object it points to has been allocated with new (if it has been allocated in another way, it should not be deleted with delete), or
    • if there are other pointers that also point to the same object (in which case only one of them should call delete. Which one?)

    So even if you wanted to, there is no way to automatically delete an object when a pointer to it is destroyed.

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

Sidebar

Related Questions

I have a query that originally looks like this: select c.Id, c.Name, c.CountryCode, c.CustomerNumber,
I have a query that looks like this: public IList<Post> FetchLatestOrders(int pageIndex, int recordCount)
I have a problem regarding this query. I want to get the applicant latest
I have a query regarding use of navigation Controller and tabBarController together. I will
I have a question regarding a query in LINQ: DataClasses1DataContext db = new DataClasses1DataContext();
I have a query regarding Dropping Multiple Pins On Map when Co-ordinates are given
I have a query regarding the directory returned from Path.GetTempPath() function. It returns C:\Documents
I have this query in sql server 2000: select pwdencrypt('AAAA') which outputs an encrypted
I have query regarding the disposing of an object. The scenario is as follows.
I have a query regarding to find out which is day (in given list)

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.