Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Should you free your pointers?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
James Kuyper  
View profile  
 More options Jun 24 2011, 10:07 pm
Newsgroups: comp.lang.c
From: James Kuyper <jameskuy...@verizon.net>
Date: Fri, 24 Jun 2011 22:07:46 -0400
Local: Fri, Jun 24 2011 10:07 pm
Subject: Re: Should you free your pointers?
On 06/24/2011 04:41 PM, Billy Mays wrote:

> In the case where you know that your program will be terminating after
> it is done using the pointers, should you even bother freeing the space up?

> Example:
> int main(void)
> {
>      int i, * data;
>      data = malloc(sizeof(int) * 100);
>      if(data) {
>          for(i = 0; i < 100; i++) {
>              data[i] = i'
>          }
>      }
>      /* free(data) ? */
>      return 0;
> }

It's not necessary, but I think it's easier to not make a special case
of main(); the rules for creating well-written code are easier to
remember if they don't have more special cases than they have to.

Also, there's always the possibility that code from main() may someday
get moved off to another function; if that code already contains
properly connected malloc() and free() calls, that's one less thing to
worry about during the move.
--
James Kuyper


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.