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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:56:09+00:00 2026-05-18T10:56:09+00:00

i have c function in my project which creates a struct and returns the

  • 0

i have c function in my project which creates a struct and returns the pointer.

typedef struct object 
{
 float var1; 
 float var2; 
} 
Object; 

Object *createObject(float newVar1, float newVar2) 
{
 Object *object; //create new structure 
 object = (Object*)malloc(sizeof(Object)); //malloc size for struct object
 if(object != NULL) //is memory is malloc'd
 {
  object->var1 = newVar1; //set the data for var1
  object->var2 = newVar2; //set the data for var2
  return object; //return the pointer to the struct
 }
 return NULL; //if malloc fails, return NULL
}

now the struct gets used and after a while i want to delete this structure, i made this function:

void deleteMarnix(Object *objectPointer)
{
 free(objectPointer); //free the memory the pointer is pointing to
 objectPointer = NULL; //stop it from becomming a dangling pointer
}

this last code snippet shows how i make an object, use it and try to delete it, however, it seems that it doesn’t completely free the memory. what am i doing wrong?

Object *object = createObject(21.0f, 1.87f);
//do things here with object.
deleteMarnix(object);
  • 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-18T10:56:10+00:00Added an answer on May 18, 2026 at 10:56 am

    What free() does is not free the memory held by the pointer completely, but actually makes it available for later use if we call a malloc after calling free().

    An evidence to this is you will be able to access the memory location after calling free and before setting the pointer to NULL ( assuming you haven’t already called malloc() ). Of course the values will be reset to some default values. ( On some compilers i found int was set to 0 ).

    Although there is no memory leak, this might answer your question.

    Let us know 🙂

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

Sidebar

Related Questions

I have created a a subclass of Table in my ASP.NET project which creates.
I'm trying to convert my old project to ARC. I have a function which
I have project code which creates a UDP socket to receive multicast packets. The
I have a search function in my project. In the searchable.xml, i would like
In my PHP project I have two different models that have a function with
I have the following function (from the opensource project recast navigation ): /// Derives
In a C project, I have a main() function in several files. When I
$(.container).hover( function(){ $(.child-1).hide(0); $(.child-2).show(0); },function(){ $(.child-1).show(0); $(.child-2).hide(0); }); A project I have requires that
I have a C# project in which i use several unmanaged C++ functions. More
I have a project which has a main form and some other forms. When

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.