Re: Garbage collection
- From: jacob navia <jacob@xxxxxxxxxx>
- Date: Tue, 02 Oct 2007 17:28:13 +0200
Douglas A. Gwyn wrote:
rbj@xxxxxxxxxxxxxx wrote:This ... would clearly be a useful addition to the language,
reducing the burden on programmers to manage memory and increasing
security.
A proper economic analysis must include the negative consequences
as well. Some of them have been mentioned in other responses;
I'll add that encouraging programmers to lose track of when their
dynamic objects are valid does not "increase security".
Yes, it provokes less mistakes, by doing that automatically.
Since the programmer is no longer responsible for keeping accounting of
each memory piece, less mistakes are done in big software projects,
and the software is much more reliable.
There is
also insufficient generality, since there would be no destructors,
which are sometimes essential.
Destructors can be programmed as usual. Most garbage collectors also
allow you to force a free() if you *know* that an object is destroyed.
For instance:
void FreeData(DataStructure *p)
{
fclose(p->File);
destroyHandle(p->Handle);
// etc etc...
GC_free(p);
}
This destructor would be the same, but the call to
free() could be replaced with a call to GC_free,
or (much better) the call to free would be replaced
with
memset(p,0,sizeof(DataStructure));
to avoid using it after it is destroyed.
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
.
- Follow-Ups:
- Re: Garbage collection
- From: Eric Sosman
- Re: Garbage collection
- References:
- Garbage collection
- From: rbj
- Re: Garbage collection
- From: Douglas A. Gwyn
- Garbage collection
- Prev by Date: Re: Garbage collection
- Next by Date: Re: Garbage collection
- Previous by thread: Re: Garbage collection
- Next by thread: Re: Garbage collection
- Index(es):
Relevant Pages
|