Memory Leaks And How To Prevent Them | C Programming Tutorial

  Рет қаралды 9,812

Portfolio Courses

Portfolio Courses

Күн бұрын

Пікірлер: 21
@metmay
@metmay Жыл бұрын
this is one of the best, if not the best tutorials to explain memory leaks, thank you so much for the great content
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're very welcome, I'm really glad you enjoyed the tutorial! :-)
@neilranada
@neilranada 2 жыл бұрын
Thanks for the great explanation on memory leaks! Going to fix my code now. I'm managing a small amount of data but I need to build good habit patterns.
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
You’re welcome Neil! :-D
@Avionics1958
@Avionics1958 2 жыл бұрын
You have such a deep knowledge of C. Thank you very very interesting.
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
You’re very welcome! :-D
@dopetag
@dopetag 11 ай бұрын
Good explanation and examples
@mb59621
@mb59621 7 күн бұрын
I actually have a question. How big is your memory that you have installed on this machine you are working? 4*10^12 bytes allocated for 34 iterations means 136*10^12 bytes total consumed by this process , which in computing terms if you divide by 2^40 , you would get a little less than 124 terabytes . It shows 112 TiB in virtual memory, but it should be not any less than 123 TiB . Regardless, do such big storage disks even exist ? And what happened to the other things you might have in your storage disk?
@yogeshchauhan9401
@yogeshchauhan9401 Жыл бұрын
I have a question does memory leak still happen when we close that program?
@PortfolioCourses
@PortfolioCourses Жыл бұрын
No, once the program finishes executing any memory is returned “to the operating system” essentially. :-)
@ramakrishna4092
@ramakrishna4092 Жыл бұрын
Hi sir I have one doubt how does free function know how much memory should be deallocate in c programming language and how to free the memory without using free function Can you pls do a video on this topic's it will helpful sir.. Thank you...
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Regarding how does free know how much memory to deallocate, typically when malloc/etc are used to allocate memory a bit of extra data is used to specify the size of the memory allocated, and free() can use this to free the memory. See: stackoverflow.com/questions/1518711/how-does-free-know-how-much-to-free. In terms of freeing memory without using free, we could actually use realloc() to set the block of memory to have a new size of 0. :-) If we're trying to implement functions like free/malloc/etc that is much more involved, for example: www.sunshine2k.de/articles/coding/cmemalloc/cmemory.html.
@undeadpresident
@undeadpresident Жыл бұрын
I noted that the allocate function didn't free the memory after it was over, but when memory was allocated in main function it was cleared after the program was done running. So does this mean that when a program is terminated entirely that all the memory it allocated is automatically cleared? I'm wondering, if when I work on a large program that will inevitably will crash from time to time as I test it, if I might be left with memory left allocated on the heap. This happened to me a month or so ago when I was messing with Opengl in Python and didn't use the proper command to clear it's buffers and a circle was left on my screen and my sound stopped working until I rebooted lol.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
When a program is done running all the memory it was allocated is going to be "released", which means it can be used for other purposes/programs. There are technically some really specialized systems where this is not the case, but this is how it works in modern operating systems (Windows, Linux, MacOS, etc.). Whether it's cleared or not by setting all values to 0, I think would ultimately depend on the OS. And I don't think an OS will spend the time to "zero the memory" either as that would take time to do it in all cases. superuser.com/a/621384
@undeadpresident
@undeadpresident Жыл бұрын
@@PortfolioCourses Thanks!
@woradev2874
@woradev2874 2 жыл бұрын
Thank you
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
You're welcome! :-D
@desubakadesu
@desubakadesu 2 жыл бұрын
Thank you
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
You're welcome! :-D
@Tu10248
@Tu10248 6 ай бұрын
👏👏
@Tu10248
@Tu10248 6 ай бұрын
do{ data = malloc(data_size); iterations++; } while(data != NULL);
fprintf() Function Deep Dive | C Programming Tutorial
30:53
Portfolio Courses
Рет қаралды 5 М.
you will never ask about pointers again after watching this video
8:03
Thank you Santa
00:13
Nadir Show
Рет қаралды 52 МЛН
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 81 МЛН
Don't underestimate anyone
00:47
奇軒Tricking
Рет қаралды 28 МЛН
How many people are in the changing room? #devil #lilith #funny #shorts
00:39
A New Era for C and C++? Goodbye, Rust?
9:08
Travis Media
Рет қаралды 87 М.
Making a simple Dynamic Memory Allocator (malloc)
5:40
Daedalus Community
Рет қаралды 12 М.
realloc Basics
21:42
Portfolio Courses
Рет қаралды 16 М.
C_137 Memory Leak in C | C Programming Language
19:24
Jenny's Lectures CS IT
Рет қаралды 48 М.
the cleanest feature in C that you've probably never heard of
8:13
Finally Fix Your Issues With JS/React Memory Management 😤
20:13
Jack Herrington
Рет қаралды 88 М.
Memory leaks and how to prevent them
10:49
CodeVault
Рет қаралды 25 М.
Dynamic Memory Allocation | C Programming Tutorial
31:51
Portfolio Courses
Рет қаралды 92 М.
Thank you Santa
00:13
Nadir Show
Рет қаралды 52 МЛН