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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:27:38+00:00 2026-05-20T20:27:38+00:00

I feel a little stupid for making a question about the deletion of pointers

  • 0

I feel a little stupid for making a question about the deletion of pointers but I need to make sure I’m deleting in the correct way as I’m currently going through the debugging process of my program.

Basically I have a few arrays of pointers which are defined in my header file as follows:

AsteroidView *_asteroidView[16];

In a for loop I then initialise them:

for(int i = 0; i < 16; i++)  
{  
      _asteroidView[i] = new AsteroidView();  
} 

Ok, so far so good, everything works fine.
When I eventually need to delete these in the destructor I use this code:

for(int i = 0; i < 16; i++)  
{  
        delete _asteroidView[i];  
}

Is this all I need to do? I feel like it is, but I’m worried about getting memory leaks.

Out of interest…
Is there much of a difference between an Array of Points to Objects compared with an Array of Objects?

  • 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-20T20:27:38+00:00Added an answer on May 20, 2026 at 8:27 pm

    This is correct. However, you may want to consider using Boost.PointerContainer, and save you hassle the hassle of manual resource management:

    boost::ptr_vector<AsteroidView> _asteroidView;
    for(int i = 0; i < 16; i++)
    {
        _asteroidView.push_back(new AsteroidView());
    }
    

    You do not have to manage the deletion, the container does that for you. This technique is called RAII, and you should learn about it if you want to have fun using C++ 🙂

    About your edit: There are several difference, but I guess the most important are these:

    1. An array of pointers can contain objects of different types, if these are subclasses of the array type.
    2. An array of objects does not need any deletion, all objects are destroyed when the array is destroyed.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I feel a little stupid asking this question, but I hope that this might
This may be a very stupid question and it's making feel like my brain
I feel a little stupid for having to ask this… But I can't seem
This might sound a little stupid but I am still curious about what the
I feel a little stupid asking this, but the Debug-menu in my Visual Studio
I feel like this is a stupid simple question, but I've been doing so
I feel a little silly asking this question, but from everything I've read, this
I'm a seasoned programmer and therefore feel a little embarrassed asking this question but
I feel a little bit silly asking this, but I haven't been able to
Started learning Wicket after ASP.NET MVC and feel a little bit confused about managing

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.