When to free memory in C
HTML-код
- Опубликовано: 4 сен 2019
- This issue has cropped up many times where beginnners were confused as to why we use free in certain situations and why we don't. Hopefully, this video helps clarify the problem.
Check out our Discord server: / discord
You just managed to explain to me in less than 15 minutes more than my professor ever succeed to explain to me in 3 hours. Thank you so much! you're awesome
thank you so much for the video, this channel is going to be a constant visit point on my cs career path
This answers 100000 dev people's questions.
You are a wonderful person
Thank you sir for delivering this valuable information
Hope u deliver more
I think I jumped something in my studies, I didn't learn about these different kind of memories and I'm now in memory allocation. 😂
In school (especially in high school) few are taught about these differences. Only later on after students have used it do they learn about it (if ever)
I was very confused when my programming teacher told me to use free() on some pointer without explaining anything
This is because p and q are stack variables pointing to a "clump" of _heap_ memory malloc'ed, right? So that when the function (here, the main() function - hence, the program) goes out of scope, its stack variables are destroyed or dealloc'ed.
Yes. Those stack variables are deallocated but the malloc-ed clump of memory isn't, thus you get a memory leak
Caught me off guard, m-alloc?
It comes from "memory allocation"... so, m-alloc seems right to me. Especially since there is calloc which sounds wrong if pronounced as a full word. Pronounce however you'd like
This does not work for CodeBlocks, right? It appears this only works in VS. Correct?
Yes this is only compatible with the Visual C++ compiler. There are alternatives like valgrind for gcc
@@CodeVault Oh I'll try that. Thanks!
are you linus tolvars?