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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:59:21+00:00 2026-05-19T04:59:21+00:00

Coming from a C# background, I have only vaguest idea on memory management on

  • 0

Coming from a C# background, I have only vaguest idea on memory management on C++– all I know is that I would have to free the memory manually. As a result my C++ code is written in such a way that objects of the type std::vector, std::list, std::map are freely instantiated, used, but not freed.

I didn’t realize this point until I am almost done with my programs, now my code is consisted of the following kinds of patterns:

struct Point_2
{
    double x;
    double y;
};

struct Point_3
{
    double x;
    double y;
    double z;
};

list<list<Point_2>> Computation::ComputationJob
    (list<Point_3>pts3D, vector<Point_2>vectors)
{
    map<Point_2, double> pt2DMap=ConstructPointMap(pts3D);
    vector<Point_2> vectorList = ConstructVectors(vectors);
    list<list<Point_2>> faceList2D=ConstructPoints(vectorList , pt2DMap);
    return faceList2D;
}

My question is, must I free every.single.one of the list usage ( in the above example, this means that I would have to free pt2DMap, vectorList and faceList2D)? That would be very tedious! I might just as well rewrite my Computation class so that it is less prone to memory leak.

Any idea how to fix this?

  • 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-19T04:59:22+00:00Added an answer on May 19, 2026 at 4:59 am

    No: if objects are not allocated with new, they need not be freed/deleted explicitly. When they go out of scope, they are deallocated automatically. When that happens, the destructor is called, which should deallocate all objects that they refer to. (This is called Resource Acquisition Is Initialization, or RAII, and standard classes such as std::list and std::vector follow this pattern.)

    If you do use new, then you should either use a smart pointer (scoped_ptr) or explicitly call delete. The best place to call delete is in a destructor (for reasons of exception safety), though smart pointers should be preferred whenever possible.

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

Sidebar

Related Questions

I am coming from C# background and I have hard time figuring out how
Coming from a Perl background, I have to say I prefer cpan Foo::Bar to
Coming from a VB background and being forced to learn C# I have hit
Coming from a background, I'm familiar with GUI editors that do a poor job
I'm coming from a C++ background to python I have been declaring member variables
I have a question about Objective-C today involving NSMutableArray. Coming from a .net/c# background
Coming to Haskell from a background in various OO languages, one thing that seems
I have a rather simple C++-problem, but coming from a C-background I am not
Coming from a Delphi background, I am used to be able to have class
I'm coming from a C# background and I really like the type inference that

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.