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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:38:41+00:00 2026-05-27T15:38:41+00:00

This is a followup to the question I just asked here . I’ve created

  • 0

This is a followup to the question I just asked here.

I’ve created a simple program to help myself understand memory allocation, malloc() and free(). Notice the commented out free line. I created an intentional memory leak so I can watch the Windows reported “Mem Usage” bloat slowly to 1GB. But then I found something stranger. If I comment out the loop just above the free line, so that I don’t initialize my storage block with random ints, it appears that the space doesn’t actually get “claimed” by the program, from the OS. Why is this?

Sure, I haven’t initialized it the block, but I have claimed it, so shouldn’t the OS still see that the program is using 1GB, whether or not that GB is initialized?

#include <stdio.h>
#include <stdlib.h>

void alloc_one_meg() {
    int *pmeg = (int *) malloc(250000*sizeof(int));
    int *p = pmeg;

    int i;
    // for (i=0; i<250000; i++) /* removing this loop causes memory to not be used? */
    //    *p++ = rand();
    // free((void *)pmeg); /* removing this line causes memory leak! */
}

main()
{
    int i;
    for (i=0; i<1000; i++) {
        alloc_one_meg();
    }
}
  • 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-27T15:38:41+00:00Added an answer on May 27, 2026 at 3:38 pm

    Allocated memory can be in two states in Windows: Reserved, and Commited (see the documentation of VirtualAlloc about MEM_RESERVE: "Reserves a range of the process's virtual address space without allocating any actual physical storage in memory or in the paging file on disk.").

    If you allocate memory but do not use it, it remains in the Reserved state, and the OS doesn’t count that as used memory. When you try to use it (whether it is only on write, or on both read and write, I do not know, you might want to do a test to find out), it turns into Commited memory, and the OS counts it as used.

    Also, the memory allocated by malloc will not be full of 0’s (actually it may happen to be, but it’s not guaranteed), because you have not initialised it.

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

Sidebar

Related Questions

This is a followup to my question here . I would like to understand
This is a followup question to one I previously asked: start-program-if-not-already-running-in-java I didn't get
This is a follow up to a question I asked earlier seen here: Confused
This is a followup to a question I asked yesterday: Have you ever had
This is a follow up to a question I just posted. I'm wondering how
This is a follow up from a question of mine that was just answered
This is a followup question of How to encode characters from Oracle to Xml?
This is a followup question to my other widget-related question . I'd like to
This is a followup question to my other question : Run bat file in
This is a followup to this question . I seem to be stuck on

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.