+ 2
C free pointer
why free pointer? what if i don't free them?
2 Réponses
+ 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.
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.