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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:25:41+00:00 2026-06-08T02:25:41+00:00

Possible Duplicate: C++ delete – It deletes my objects but I can still access

  • 0

Possible Duplicate:
C++ delete – It deletes my objects but I can still access the data?
Can a local variable's memory be accessed outside its scope?

I do not understand what delete really does when I want to free memory allocated with new. In C++ Premiere book it is written:

This removes the memory to which ps pointer points; it doesn’t remove the
pointer ps itself. You can reuse ps, for example, to point to another new allocation. You
should always balance a use of new with a use of delete; otherwise, you can wind up with
a memory leak—that is, memory that has been allocated but can no longer be used. If a
memory leak grows too large, it can bring a program seeking more
memory to a halt.

So as I understand delete must delete the value in the memory to which pinter points. But it doesn’t. Here’s my experiment:

int * ipt = new int;   // create new pointer-to-int

cout << ipt << endl;   // 0x200102a0, so pointer ipt points to address 0x200102a0
cout << *ipt << endl;  // 0, so the value at that address for now is 0. Ok, nothing was assigned
*ipt = 1000;     // assign a value to that memory address
cout << *pt << endl;   // read the new value, it is 1000, ok
cout << *((int *) 0x200102a0) << endl;   // read exactly from the address, 1000 too

delete ipt;   // now I do delete and then check
cout << ipt << endl;  // 0x200102a0, so still points to 0x200102a0
cout << *ipt << endl;  // 1000, the value there is the same
cout << *((int *) 0x200102a0) << endl;    // 1000, also 1000 is the value

So what does delete really do?

  • 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-06-08T02:25:42+00:00Added an answer on June 8, 2026 at 2:25 am

    Think of memory as a big warehouse with lots of boxes to put things into. When you call “new”, the warehouse staff finds an unused box large enough for your needs, records that box as being owned by you (so it’s not given to someone else), and gives you the number of that box so you can put your stuff into it. This number would be the “pointer”.

    Now, when you “delete” that pointer, the reverse happens: the warehouse staff notes that this particular box is available again. Contrary to real warehouse staff they aren’t doing anything with the box — so if you look into it after a “delete” you might see your old stuff. Or you might see somebody else’s stuff, if the box was reassigned in the meantime.

    Technically, you are not allowed to look into your box once you have returned it to the pool, but this is a somewhat weird warehouse with no keys or guards, so you can still do whatever you want. However, it might cause problems with the new owner of the box, so it’s expected that you follow the rules.

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

Sidebar

Related Questions

Possible Duplicate: C++ delete - It deletes my objects but I can still access
Possible Duplicate: C++ delete - It deletes my objects but I can still access
Possible Duplicate: What's the best way to delete all data from a table? Clear
Possible Duplicate: How to delete a zip file using php How can I remove
Possible Duplicate: SQL Delete: can't specify target table for update in FROM clause I
Possible Duplicate: how to delete item from listView? I fetch data from Database in
Possible Duplicate: ( POD )freeing memory : is delete[] equal to delete ? Does
Possible Duplicate: Any reason to overload global new and delete? In c++ you can
Possible Duplicate: PHP: Is there a command that can delete the contents of a
Possible Duplicate: SQL Delete: can't specify target table for update in FROM clause I'm

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.