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

  • Home
  • SEARCH
  • 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 8570765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:37:56+00:00 2026-06-11T18:37:56+00:00

Possible Duplicate: Proper stack and heap usage in C++? Heap vs Stack allocation I’m

  • 0

Possible Duplicate:
Proper stack and heap usage in C++?
Heap vs Stack allocation

I’m trying to understand why a Library I ported from Java to C++ (long and arduous editing work after using a converter) doesn’t free up memory and just explodes the Virtual Memory till crash.
Obviously this has to do with Java having a GC and C++ not – and the algorithms are pretty straight converted to C++.

So here’s my question. Where and how do I delete allocated memory (Free it)? When I have:

Matrix *mat = new Matrix(args);

I obviously need to end the scope with a delete mat;. Can I avoid this?
Would using Matrix mat(args); be better? in terms of Memory Allocation and freeing?
Or using Matrix mat = Matrix(args)?

  • 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-11T18:37:58+00:00Added an answer on June 11, 2026 at 6:37 pm

    Where and how do I delete allocated memory? (Free it)

    In most cases, if you coded things properly, you don’t have to explicitly free or de-allocate any memory. Either use automatic allocation, or smart pointers. Otherwise, the answer to where is rather unsatisfying: wherever you need to, depending on your program. The answero to how is simpler: with delete (or delete[] for dynamically allocated arrays).

    … I obviously need to end the scope with a delete mat;
    Can I avoid this?

    Yes, if you use automatic allocation:

    Matrix mat(args);
    

    As a general rule, you should only use dynamically allocated objects if you really need to. If you don’t know if you really need to, then you probably don’t.

    … Or using Matrix mat = Matrix(args);

    This performs a copy initialization, and in this context provides no advantages over Matrix mat(args);. The RHS of the expression is a temporary Matrix object, which gets used to copy construct the LHS mat.

    Here is a recent related post.

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

Sidebar

Related Questions

Possible Duplicate: What Java FTP client library should I use? I am looking for
Possible Duplicate: iOS: How to get a proper Month name from a number? How
Possible Duplicate: What is the proper way to return an object from a C++
Possible Duplicate: How do I compare strings in Java? I read some records from
Possible Duplicate: Proper Use of yield return What is the use of the yield
Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:
Possible Duplicate: Why would you ever want to allocate memory on the heap rather
Possible Duplicate: C# - Proper Use of yield return What can be a real
Possible Duplicate: What is the proper declaration of main? I am working on my
Possible Duplicate: What's the proper way to minimize to tray a C# WinForms 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.