Consider this snippet,
char *p1="";
printf("p1=%p\np1=%s\n",p1,p1);
char s1[6]="abcde";
printf("s1=%p\ns1=%s\n",s1,s1);
p1=s1;
printf("p1=%p\np1=%s\n",p1,p1);
Since, none of the variables are allocated on heap, all allocated space will be freed at the end of process.
Questions:
Your strings ""
and "abcde"
live in the (read-only) data section of your executable. They are loaded into memory when your program is loaded.
When no more pointers point to it, then no more pointers point to it. That's all.
Programs have lots of read-only data (for example, the entire program's code!) It's not really something to be concerned with.
This is not considered a memory leak, just as having a function that never gets called is not a memory leak. After the program is loaded, nothing is ever allocated or de-allocated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With