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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:57:28+00:00 2026-06-17T22:57:28+00:00

My class has a generic array of pointers member named A : T** A

  • 0

My class has a generic array of pointers member named A:

T** A

Currently, i delete the array in the destructor in the following way:

~MyQuickInitArray(){
    delete [] A;
};

Will this cause a memory leak? if so, should i iterate through the array and call delete on each object?

On a side note – Do I need to call delete [] B if B is an array of integers or does the destructor handles it already?

EDIT:

This is how the allocation occurs:

MyQuickInitArray(int size)
{
    if(size <= 0)
    {
        throw new std::exception;
    }

    _size = size;
    _counter = 0;
    A = new T*[size];
    B = new int[size];
    C = new int[size];
}
    MyQuickInitArray(const MyQuickInitArray& myQuickInitArray)
    {
        _size = myQuickInitArray._size;
        _counter = myQuickInitArray._counter;
        A = new T*[_size];

        for(int i = 0; i<_size ;i++)
        {
            if(myQuickInitArray.A[i] != NULL)
            {
                A[i] = new T(*myQuickInitArray.A[i]);
            }
        }

        B = myQuickInitArray.B;
        C = myQuickInitArray.C;
    }
  • 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-17T22:57:29+00:00Added an answer on June 17, 2026 at 10:57 pm

    Will this cause a memory leak?

    You can surely count on it if A is an array of pointers. You need loop through the array and delete the pointers yourself.

    ~MyQuickInitArray {
        for (int i =_size; i--;) {
            delete A[i];
        }
        delete [] A;
    }
    

    Do I need to call delete [] B if B is an array of integers or does the destructor handle it?

    Yes, always delete that which is allocated with new. You can do this inside your class’s destructor.

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

Sidebar

Related Questions

I'm creating a generic list class that has a member of type Array(Array of
I'm trying to write a class that has a generic member variable but is
I'm trying to specify that a generic class has to be an array, or
I'm writing a topic-based publish/subscribe system in C++. My generic Event class has three
I have a list-generic that has a property (class type). I need a sort
I am wrapping a native C++ class, which has the following methods: class Native
Is it possible to set a member attribute in a generic way? I am
I have a Model class for a Generic Object that contains an array of
Is it possible, in any way, to pass a Generic Record in an array
Having problems with array of pointers. I have a custom class called C .

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.