free is needed when app will exit?
-
Hi guys, I have a qustion in windows programing like this. I think
free
was always needed win16 programing becausemalloc
was implmented byGlobalAlloc
and system never free its pointer untilGlobalFree
called. So it makes a system memory leaks. But nowadays, in win32 system,malloc
is implemented byHeapAlloc
and do not need call at program exiting anymore, because system frees its heap safely at process died. Is this true or not? -
Hi guys, I have a qustion in windows programing like this. I think
free
was always needed win16 programing becausemalloc
was implmented byGlobalAlloc
and system never free its pointer untilGlobalFree
called. So it makes a system memory leaks. But nowadays, in win32 system,malloc
is implemented byHeapAlloc
and do not need call at program exiting anymore, because system frees its heap safely at process died. Is this true or not?norish wrote:
But nowadays, in win32 system, malloc is implemented by HeapAlloc and do not need call at program exiting anymore, because system frees its heap safely at process died.
Strictly you are correct - Windows releases a processes resources when the process terminates. However, it's good practise to release resources explicitly, just in case the code gets reused somewhere that it matters. Use smart pointers/resource handles and it becomes easy enough.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
norish wrote:
But nowadays, in win32 system, malloc is implemented by HeapAlloc and do not need call at program exiting anymore, because system frees its heap safely at process died.
Strictly you are correct - Windows releases a processes resources when the process terminates. However, it's good practise to release resources explicitly, just in case the code gets reused somewhere that it matters. Use smart pointers/resource handles and it becomes easy enough.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
Thanks for reply. I might be correct after all. :) However, it's good practise to release resources explicitly Your point is the very good manner in most case, I know, especially some system handles (like kernel objects) must explicitly release in the code before progaram exits. So sometimes I use smart pointers for managing such handles. ;)