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 4110118
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:53:33+00:00 2026-05-20T21:53:33+00:00

I discussed with my coworker about how to delete an entry in a map

  • 0

I discussed with my coworker about how to delete an entry in a map
the map has the int as the index and a pointer pointing to an object.

I said, first release the object, and then delete the entry.
My coworker said first delete the entry and then release the object.

So what’s the best way? Any trick for this question?

  • 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-20T21:53:33+00:00Added an answer on May 20, 2026 at 9:53 pm

    Unless you have a multi-threaded environment, either way would work. The rule of thumb is that, once your function returns, there should be no dangling pointers left, i.e. no pointers to the object that just was deleted.

    The only problem that could occur is that if you delete the entry first, you have to make sure to have a temporary copy of the pointer, as you will not be able to retrieve it from the map after the entry has been deleted.

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

Sidebar

Related Questions

I recently discussed with a colleague about mocking. He said that mocking classes is
ASP.NET MVC has been discussed on this forum a few times. I'm about to
Object-relational mapping has been well discussed, including on here. I have experience with a
I know this topic has been discussed but I think it has some differences.
I'm implementing the first option discussed in Marking for deletion in Django , that
I know this has been discussed a lot of times but is there any
I know this has been discussed earlier but I couldn't find a satisfactory answer.
I understand this has been discussed before but since this post in late 2010
This problem probably has been discussed, but this one is slightly different. I'm using
First a little about myself. I am not an experienced software engineer, architect or

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.