S
Spriggan
if you make dynamic alloc memory,
you must dealloc memory.
if you don't dealloc memory, your system will be nockdown.
OS is probably dealloc memory in your application if it is automatic
variables at application terminated.
but dynamic alloc memory is not dealloc by OS at application teminated. why?
that is not Automatic Variable. Indicate it, Dangling Pointer.
that is, only your resposiblity.
otherwise, reference by this code.
int *data = (int*)malloc ( sizeof(int) * 100 );
..
..
..
free(data);
data = NULL;
is correct.
( reference by MSDN )
if you want to use easy, make macros.
ex) #define SAFE_DELETE(p) if(p) { free(p);
(p)=NULL; }
if you run function "free()", pointer is must be NULL. that is more cleary.
you must dealloc memory.
if you don't dealloc memory, your system will be nockdown.
OS is probably dealloc memory in your application if it is automatic
variables at application terminated.
but dynamic alloc memory is not dealloc by OS at application teminated. why?
that is not Automatic Variable. Indicate it, Dangling Pointer.
that is, only your resposiblity.
otherwise, reference by this code.
int *data = (int*)malloc ( sizeof(int) * 100 );
..
..
..
free(data);
data = NULL;
is correct.
( reference by MSDN )
if you want to use easy, make macros.
ex) #define SAFE_DELETE(p) if(p) { free(p);
(p)=NULL; }
if you run function "free()", pointer is must be NULL. that is more cleary.