![]() |
| | #1 |
| Guest
Posts: n/a
| Okay, heres two structures : Code:
struct TEST
{
char *var1;
DATA *data;
};
struct DATA
{
char *datavar;
};
lets say I allocate the memory and everything. When I get to the point that I need to free() it I have a questions. lets say we have... struct TEST test1; if I free(test1); does it free *var1, and *data too? or do I need to seperately free them as well? also, if I were to... test1=NULL; will it NULL var1 and data too? or, again, do I need to do those seperatley? Thanks, any help on these minor questions will be most appreciated, as well as any other insights. -Jase |
|
| | #2 |
| C++ Developer Join Date: Jun 2002 Location: UWaterloo
Posts: 2,718
| If you allocate memory for any members explicitly, you need to free it, along with the struct itself.
__________________ Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie |
| XSquared is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Increasing memory allocation in function | Ramses800 | C Programming | 3 | 12-16-2008 05:30 AM |
| Assignment Operator, Memory and Scope | SevenThunders | C++ Programming | 47 | 03-31-2008 06:22 AM |
| C memory allocation to c++ | markucd | C++ Programming | 2 | 11-30-2005 05:56 AM |
| Understanding Memory Allocation | Ragsdale85 | C Programming | 7 | 10-31-2005 08:36 AM |
| Pointer's | xlordt | C Programming | 13 | 10-14-2003 02:15 PM |