On Feb 28, 6:17*pm, jacob navia <ja...@spamsink.net> wrote:
> Le 28/02/11 16:46, Leigh Johnston a crit :
>
> >> There is no point in deleting anything since it is the main() function
> >> and the OS will cleanup stuff anyway.
>
> > Here are three adjectives that describe you as a programmer:
>
> > 1) cowboy
> > 2) sloppy
> > 3) slapdash
>
> > I will let you choose which one you want.
>
> > /Leigh
>
> There are several memory management and memory use strategies. I have
> enumerated the most used ones in my tutorial (about the C language,
> not the C++ language) available here:
>
> http://www.cs.virginia.edu/~lcc-win32/
>
> Some of the principles there apply here, specifically the 'Never free()'
> strategy.
>
> This strategy avoids all problems associated with free() (in C++
> "delete") by never freeing or deleting any memory and allowing the
> OS to clean up everything much more efficiently.
>
> This strategy is indicated for transient programs, that allocate a
> lot of memory, and almost never release anything until they exit.
Yes, but this fails when:
* code is run on an OS where closing a process does not free said
memory (yes, that exists, and you seem to presume it does not)
* total heap needed surpasses total heap available, but peak heap does
not; that can happen e.g. when
** code is changed
** data set got bigger
** code is run in an environment where available heap is reduced by
administrative means
* objects not deleted hold otherwise scarce resources (e.g. DB
connection etc handles). By the way, are you sure that OS cleans up
such resources? I sure am not, OS knows nothing of such things
* code is taken out to be used in a different context (e.g. something
long-running)
It's bad advice, __especially__ when given to students (your link is
coming from an "edu" domain). It's exactly cowboy style, as evoked:
play fast and loose, damn the consequences. No thanks. How about at
least starting and ending the lecture on this strategy with "don't do
this at home"?
Goran.