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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:29:52+00:00 2026-06-03T04:29:52+00:00

Please explain memory allocation with instance creation class simpleTestFactory { public: static simpleTest* Create()

  • 0

Please explain memory allocation with instance creation

class simpleTestFactory
{
    public: 
    static simpleTest* Create()
    {
        return new simpleTest();
    }
}

class simpleTest
{
    private:
    int x,y,z;
    public:
    int printTest()
    {
        cout<<"\n This test program";
    }
}

int main()
{

    simpleTest* s1=simpleTestFactory::Create();
    .
    .   
    s1=simpleTestFactory::Create();
}   

In the main function we are creating instance for the simpleTest with create static function. Again we are creating another instance for the same object.

In this case the first created instance memory would be deleted??

otherwise how to avoid memory issues??

  • 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-03T04:29:53+00:00Added an answer on June 3, 2026 at 4:29 am

    In this case the first created instance memory would be deleted?

    No, it won’t. You have to deallocate it yourself by calling delete, or by using a smart pointer in the first place.

    (I assume that s1 is of type simpleTest*, i.e. a pointer to simpleTest, as otherwise your code is not valid C++.)

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

Sidebar

Related Questions

Please explain what this task is about? Create a generic linked list class that
Please explain the SQL query given below. I m new with SQL and struggling
Please explain why dictionary's 'getAt' method fails List<BString> infoKeys = new List<BString>(infoDict.Keys); if (infoKeys.Contains(TorrentFileKeyWords.FILES_KEY)
Could someone please explain how to correctly allocate memory for for a pointer to
Can someone please explain to me how does Java garbage collector realize those memory
Can somebody please explain me the difference between the terms high memory and high
Possible Duplicate: Memory randomization as application security enhancement? hi, Can some explain me please
Could you please explain the differences between using both "16 KB shared memory +
Please explain what is meant by tuples in sql?Thanks..
Please explain what is name mangling, how it works, what problem it solves, and

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.