+ 2

C free pointer

why free pointer? what if i don't free them?

29th Sep 2018, 8:37 AM
Ader
Ader - avatar
2 odpowiedzi
+ 5
When you allocate memory you take some part of available space from the system. But you don't have an infinite amount of Ram, so free should be used to return that part to the system. If you don't make that you may run out of memory sooner or later.
29th Sep 2018, 8:58 AM
WittyBit
WittyBit - avatar
0
SIDE NOTE: If you're planning to use the same pointer later in the program, it's recommended to set it to another adress or to nullptr (or null, in case you have an older version of the compiler) AFTER deleting it. the lack of assignment to the pointer can cause an undefined behavior.
22nd Dec 2018, 6:25 PM
Santiago Muñez
Santiago Muñez - avatar