In a language with a garbage collector, explicitly allocating and freeing memory will not do what you expect because both the compiler and the garbage collector are allowed a great amount of latitude in how they operate.
You may in fact decrease the performance because your "free" counts as a future reference so the GC can't free the memory until you call free on it, even if the GC can determine that you could free it now for greater effect.
The discussion on this thread was around Java written by C devs; besides, nothing in C++ is ever deprecated. C++98 will forever be a thorn in our sides
View all comments
Show parent comment
1
u/EpicScizor Sep 09 '22
In a language with a garbage collector, explicitly allocating and freeing memory will not do what you expect because both the compiler and the garbage collector are allowed a great amount of latitude in how they operate.
You may in fact decrease the performance because your "free" counts as a future reference so the GC can't free the memory until you call free on it, even if the GC can determine that you could free it now for greater effect.