Re: Lock-free reference counting
- From: Juha Nieminen <nospam@xxxxxxxxxxxxxx>
- Date: Mon, 24 Nov 2008 01:56:24 GMT
Mark Wooding wrote:
To be honest, I can't say that I care greatly exactly when objects get
freed up.
Memory is not the only resource that can be reserved and freed. There
are situations where an object must free some resource (other than
memory) as soon as the object is not used anymore because even a
temporary leak of that resource might be fatal.
Having to manually tell the object to free the resource is obviously
error-prone (especially in languages where there may be surprising exit
points from functions, such as a thrown exception).
Some languages offer tools to help these cases, but their usage is
sometimes limited. For example, if I'm not mistaken, the C# language
offers the "using" block for this exact purpose: When the block is
exited, any object defined with the "using" will be immediately
finalized, regardless of how the block is exited. In Java I think the
"finally" block can be used for a similar purpose.
Of course the problem with these is that they are limited to local
scope. You can't achieve a "finalize the object immediately after the
last reference to it dies" effect using those commands if the object is
shared among two different modules.
Another technique which is often hard to achieve with GC'd languages
which treat objects mostly as references-to-objects is the copy-on-write
idiom. For instance, one problem is that having ghost objects outliving
the scope of their references may cause unnecessary deep-copies of the
data, even though only one live object was actually referencing the data
(and thus deep-copying it would not be necessary). Also achieving the
automatic reference counting needed for copy-on-write can be rather
laborious in itself in many such languages.
If I'm not mistaken, if you want to use the copy-on-write technique in
a language like Java, the GC is actually more a hindrance than an aid.
.
- Follow-Ups:
- Re: Lock-free reference counting
- From: Mark Wooding
- Re: Lock-free reference counting
- From: Jon Harrop
- Re: Lock-free reference counting
- References:
- Lock-free reference counting
- From: Juha Nieminen
- Re: Lock-free reference counting
- From: Jon Harrop
- Re: Lock-free reference counting
- From: Juha Nieminen
- Re: Lock-free reference counting
- From: Jon Harrop
- Re: Lock-free reference counting
- From: Juha Nieminen
- Re: Lock-free reference counting
- From: Mark Wooding
- Re: Lock-free reference counting
- From: Juha Nieminen
- Re: Lock-free reference counting
- From: Mark Wooding
- Re: Lock-free reference counting
- From: Juha Nieminen
- Re: Lock-free reference counting
- From: Mark Wooding
- Lock-free reference counting
- Prev by Date: Re: Lock-free reference counting
- Next by Date: Re: find polygon
- Previous by thread: Re: Lock-free reference counting
- Next by thread: Re: Lock-free reference counting
- Index(es):
Relevant Pages
|