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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:19:11+00:00 2026-06-03T01:19:11+00:00

I am creating a program that uses an array of objects declared with Element

  • 0

I am creating a program that uses an array of objects declared with

Element * elements = new Element[number];

where an element is a class that has/needs a its own destructor.

when I go to delete this would I use just use array delete, and have the program worry about calling the destructor:

delete [] elements;

or do I call the destructor for each item explicitly with keyword delete:

for(int ii = 0; ii< ArraySize; ii++)
    delete elements[ii];
delete [] elements;

Note: I understand that I could probably use something like boost::ptr_vector, but I wanted similar to hashTable functionality (so the for loop would need additional information, but that is outside of the direct scope of this question) which is why I am using a traditional array. I would still like to know which behavior is needed to avoid memory leaks.

  • 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-03T01:19:13+00:00Added an answer on June 3, 2026 at 1:19 am

    The first one. You should

    delete [] elements;
    

    The second one is incorrect and should give you errors if you try to compile it.

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

Sidebar

Related Questions

I am creating a Java program that uses a GUI to display a mortgage
I have been working on a Android Web Services program that uses a number
I am creating a program that uses JFrame, JPanel, JLabel and all other sorts
I am creating a .NET program that uses odp.net, specifically the 11g version. Our
I'm creating a setup program in VS2008 for a C# application that uses SQLite,
I'm creating a basic C program that uses the mysql api. I'm on windows,
im creating a program that will compile java files, at the moment i have
I am creating a program that calculates rainfall for the year etc. I had
I'm creating a program that authenticates from a before it runs. I also want
I am currently creating a program that dynamically adds Image to a dockPanel every

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.