Jump to content
  • Advertisement
Sign in to follow this  
mrtie_dye

deleting pointers

This topic is 4852 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does this accomplish the same thing as deleting a pointer? int *ptr; ptr = new int; ptr = NULL; //does this do the same thing as deleting it? Thanks for any help

Share this post


Link to post
Share on other sites
Advertisement
No, setting it to NULL will not deallocate the memory allocated by new. To be safe, you should usually delete then set it to NULL (deleting a pointer that's already been deleted can cause a crash, deleting NULL does nothing).

Share this post


Link to post
Share on other sites
No it does not. What that does is essentially to give you a memory leak (since you suddenly have allocated memory you probably does not know how to release). To release the memory allocated by new, you need to call delete.

So the statement "delete ptr" before you set it to NULL will cause the memory to be released.

Share this post


Link to post
Share on other sites
You're only setting the pointer to point at memory address 0, which means that you've just made a memory-leak! The real way to delete is to use delete like this:
delete ptr;

Yeah slowwwww :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!