Re: [Dev-C++] singleton pattern implementation.
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Chris M. <lor...@gm...> - 2007-09-28 15:26:32
|
On 9/28/07, Younes Ouadi <ou...@em...> wrote: > On Thu, 2007-09-27 at 20:42 -0700, Chris Miller wrote: > > On 9/27/07, Per Westermark <pw...@ia...> wrote: > > I've always been told to never trust anything to clean up your memory > > for you. It'll probably leave me to clean up a lot of memory when I > > don't need to, but learning how to deal with memory, with particular > > regards to scope and when things come in and out of scope, will never > > hurt IMHO. > > > Chris, > > We are talking here about something basic: modern OS (UNIX, Linux, > Windows ...) insures getting back memory allocated to a process once > this process is over. > > Don't confuse this fact with the fact that memory leak is one of the > issues that C and C++ developers should take seriously. Memory leak is > the fact that a process allocates memory dynamically and left it behind > without releasing it and this while the process is still running. This > means that while the process is still running, it takes memory from the > OS and waste it. Understood. > However, once the process is over, modern OS take back this memory. This > is not the case of Embedded OS since these later do not enjoy the same > conditions like the non Embedded OS. Makes sense. > Now, let me highlight the issue mentioned by /pwm. There are some > resources that the OS cannot get back or cannot get back easily. Let us > mention here: > * a process that creates a temporary file and, by design, this process > should delete this file before it ends. If this process doesn't do so, > the OS cannot do it in its place. And here come up the importance of the > concept of destructor. It can be used by a given application to release > this kind of resources since the compiler insures calling a class > destructor while releasing objects of this class > * a process that opens a socket should close it properly before it ends. > Otherwise, it will stay in the OS for a while before that this later > release it which is not a good behavior of the process. Okay. -- Registered Linux Addict #431495 If You Know What's Good For You, You'll Install Linux John 3:16! |