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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:03:10+00:00 2026-05-26T22:03:10+00:00

In code I’m working on right now I have a method belonging to a

  • 0

In code I’m working on right now I have a method belonging to a class that itself creates an instance of another object to use within the method. Does the memory belonging to that object get automatically get released after the method returns and the object looses scope? Or will I be taking up more and more memory each time the method is called?

The code has this structure:

int Class::method(int input) {
    Other_Class local_instance;
    int i;

    i = local_instance.do_something();
    i *= input;

    return i;
}

So will the memory belonging to local_instance be released upon returning from the method? Or will I have many instances of Other_Class clogging up memory?

Thanks very much for your time and help!

  • 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-26T22:03:11+00:00Added an answer on May 26, 2026 at 10:03 pm

    Well, to begin with, local_instance is not an object of class Other_Class but a function without arguments returning Other_class. This is also known as C++’s most vexing parse.

    EDIT: The code in the question has been corrected; the original version had

    Other_Class local_instance();
    

    But let’s assume that this line actually read

    Other_Class local_instance; // no parentheses
    

    Then yes, this object will be automatically get released at the end of the function. Note however that the same is not true for objects you allocate with new, for those objects it is your responsibility to delete them when no longer needed.

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

Sidebar

Related Questions

(code examples are python) Lets assume we have a list of percentages that add
Code below defines a ChargeCustomer class that contains an array of type customers. I
Code that was working fine last week is suddenly throwing this exception: System.Data.SqlClient.SqlException (0x80131904):
Code I have: cell_val = CStr(Nz(fld.value, )) Dim iter As Long For iter =
Code below is not working as expected to detect if it is in design
Code that is untestable really annoys me. The following things make oo-code untestable: global
I have a jquery bug and I've been looking for hours now, I can't
Code in the post has been modified. I was thinking that replacing \n with
Code auto-generated by Xcode seems to have the opening brace on the same line
Code Igniter version '2.0.3' Jquery 1.7 Jquery History plugin I have a CodeIgniter app

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.