|
|
Warp wrote:
> That really didn't answer my question. I didn't ask for the simplest
> solution.
Well, you're asking about a very complex field that's been evolving for
30 years. And the GC for each language is different.
>> [Note that I do not consider "reference counting" to be a valid GC
>> algorithm, since it doesn't actually work properly...]
>
> Yet many languages use it, such as for example PHP and Objective C.
I'm not sure PHP lets you have a pointer to another object visible at
the user layer. If you do
$x['hello'] = $y
as far as the user is concerned, $x['hello'] and $y are two different
values. So $y['hello'] = $y doesn't form a circular reference, as far as
I can remember. I'll try it out as soon as I boot over to Linux.
> It just sounds to me that people object about reference counting because
> in theory it's problematic, but some people just go ahead and use it anyways
> without problems.
Not without problems. Firefox, for example, is redoing the entire
plug-in memory management thing because it's too hard for extension
writers to get right.
> (Yes, I know that in PHP you can actually get circular references which
> get never freed, and that's a known problem, but it doesn't seem to cause
> too many problems in practice nevertheless, seeing how popular PHP is.
PHP tends to run for one web page, then exit. That's part of the
solution. Indeed, I ran across this, trying to use PHP in a loop to
insert a few million records from a file into a database.
Since PHP doesn't actually have pointers, it's possible the runtime is
doing things to patch up as well.
But saying "it's good enough, who cares if one out of 20 programs leaks
memory" is a very PHP approach, yah.
> Circular references seem to be a bit like goto: You can come up with all
> kinds of situations where it's "necessary", but in practice it happens
> rarely if at all.)
I disagree. Doubly-linked lists, trees with pointers up the nodes,
widgets with child widgets that have parent pointers, etc. Pretty much
everything "OO" is good at winds up generating circular references.
--
Darren New / San Diego, CA, USA (PST)
"That's pretty. Where's that?"
"It's the Age of Channelwood."
"We should go there on vacation some time."
Post a reply to this message
|
|