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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:40:25+00:00 2026-05-26T23:40:25+00:00

I have a very simple problem and I seem to be stumped at whatever

  • 0

I have a very simple problem and I seem to be stumped at whatever is happening. Look at the following code:

CArray<double, double&> arr;
arr.SetSize(50000);

for(int i =0; i< 50000; i++)
{
    arr[i] = (i+2)*3.14f;
}

arr.RemoveAll();

I would assume that after RemoveAll(), the memory would be freed but it seems like it is not happening. To check memory footprint, open Taskmanager and watch your exe’s Memory. It increases on arr.SetSize() call but it never decreases even when this arr goes out of scope. Can somebody shed some light on nthis?

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

    First thing:

    Task Manager != Memory Profiler

    The operating system (or more specifically the C runtime system) would certainly cache some of the memory you allocate.

    Note that the operating system usually isn’t dumb – if it’s memory that’s not being used by the application and the OS needs more memory to satisfy some other program’s memory needs, it will allocate accordingly. But if that’s not the case (it isn’t most of the time), then keeping it for the application to reuse when is a winning strategy.

    Because of these sort of optimizations, you really can’t use Task Manager to get an accurate view of an application’s memory usage.

    Second thing:

    Like all non-stupid dynamic array classes, CArray doesn’t release the memory backing the array even when you remove all the elements in case you need to use the memory buffer again. It would be an awful waste of processor cycles to delete the underlying memory buffer only to find that you need to waste even more processor cycles to reallocate another buffer to handle your next CArray::Append() call that might come right after a CArray::RemoveAll().

    Should you really want to get rid of that extra space, use CArray::FreeExtra(). Note that the function may involve allocating a new buffer and copying the elements over to the new one, then deleting the old buffer.

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

Sidebar

Related Questions

I seem to have a problem with my very simple implementation of a file
i have very simple problem. I need to create model, that represent element of
I have a very simple problem which requires a very quick and simple solution
I have a very simple problem and a solution that will work, but I'm
I have a very simple problem but cannot find a nice solution. I have
I have made a very simple AppleScript to close tabs in Safari. The problem
I have a very simple problem in which I need to do something after
Very simple problem, but can't seem to solve it. I'm probably just not thinking
Currently I have a very simple tab system set up, the problem is when
This problem seems very simple, however I cannot get this to work. I have

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.