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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:02:23+00:00 2026-05-26T09:02:23+00:00

I would like to use free() to remove the whole matrix arrays from memory.

  • 0

I would like to use free() to remove the whole matrix arrays from memory. How can i do it?

Allocate arrays:

// test.h
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>

#define BYTE unsigned char
#define  my_array(n_height, n_width) (BYTE **)create_array(sizeof(BYTE), (n_height), (n_width))

char  **create_array(int u_size, int height, int width);
char  **create_array(int u_size, int height, int width)
{
    char  **array;
    int     i;

    if (!(array=(char **)malloc(height*sizeof(char *)))) {
        printf("Memory allocation error.\n");
        exit(0);
    }
    if (!(array[0]=(char *)malloc(height*width*u_size))) {
        printf("Memory allocation error.\n");
        exit(0);
    }
    for (i=1; i<height; i++)
        array[i] = array[i-1] + width*u_size;
    return array;
}

// test.c
#include "array.h"
int main()
{
    unsigned char *bytes;
    BYTE  **matrix;
    matrix = my_array(height, width);

    int c = 0;
    for (int h=0; h < height; h++) {
        for (int w=0; w < (width); w++) {
            matrix[h][w] = bytes[c];
            c++;
        }
    }

    printf("Done.\n");

    free(matrix); // really empty memory??
}

I am not sure whether matrix has been completely removed from the memory when i use free(matrix);

  • 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-26T09:02:24+00:00Added an answer on May 26, 2026 at 9:02 am

    You must call free() exactly once per call to malloc(). You can’t “fool” free() into free:ing several blocks. If you want to be able to call free() only once, you’ll need to make sure to allocate all the required memory in a single call to malloc().

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

Sidebar

Related Questions

I would like to use components that are free for commercial use. I looked
Only for tutorial purpose, I would like to try to use a free SOAP
I would like to use $a and $b variables in my anonimous binary functions
I would like to use a TextBox for a password, but before the user
I would like to use the Tornado web server to connect to a HTTP
I would like to use the Roboto font in my Android application and make
I would like to use ListBox1.loadfromfile method in .NET, but it doesn't seem to
I would like to use a language that I am familiar with - Java,
I would like to use something like CLR Profiles on .Net 2.0 to see
I would like to use as and is as members of an enumeration. I

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.