PHP 5.3 includes garbage collection for circular references

ank on 2010-06-24T03:42:54

Now, this is what I'm talking about. I haven't done PHP in ages, but today I needed to do some quick scripting and I realized there's been a new major release sometime after my last contact with the language. Quick look at new features includes garbage collection for circular references, something that perl still doesn't include.

You see? This is the sort of things that we lose by allowing Wall and his minions to have his way. A few years ago it would have been laughable to think that PHP was somehow more advanced than perl, but that's not the case anymore.

Of course, PHP has this garbage collection disabled by default, and seems quite experimental, in a very PHP-ish way. But still, at least there's an evolution.

What's really sad is that GC algorithms are very well known and quite easy to use; the Boehm GC comes to mind immediately.

See what happens when you dream of a pluggable, perfect GC scheme for a language that's been in development for 12 years instead of finishing something that's better than perl 5 and can be done now?

Cross posted to my blog


"Allow"

petdance on 2010-06-24T04:33:08

allowing Wall and his minions to have his way.

You seem to be implying that you can somehow disallow it.

What's really sad is that GC algorithms are very well known and quite easy to use; the Boehm GC comes to mind immediately.

It sounds you're upset because your patches to Perl 5 that implemented this GC were rejected?

It's easy to get it wrong

nicholas on 2010-06-24T09:12:15

What's really sad is that GC algorithms are very well known and quite easy to use; the Boehm GC comes to mind immediately.

What you're missing from this analysis is that swapping to mark & sweep GC, particularly a conservative GC such as Boehm, means that you no longer have any guarantee of the timing of destruction of objects, or even that they'll be (formally) destroyed at all, before program exit. So many of the existing uses of DESTROY in Perl would go out of the window, and the paradigm of Resource Acquisition Is Initialization would no longer be possible. Files handles wouldn't close automatically when the go out of scope. Database handles wouldn't be released immediately that their enclosing object becomes unreferenced. If the system has a lot of free memory, it's quite possible that the GC decides that it doesn't need to run a sweep, with the result that the program runs out of a limited resource such as database handles.

Hence it's easy to do something "obvious" and get it very wrong.

What would be needed is code to detect cycles of references, which is something more subtle than general "live-ness".

And as Andy suggests, nothing is stopping you contributing patches to Perl 5 to implement this. You can get the source code from http://perl5.git.perl.org/perl.git

Re:It's easy to get it wrong

chromatic on 2010-06-24T12:08:06

Hence it's easy to do something "obvious" and get it very wrong.

Some hybrid systems use simple refcounting but occasionally run a full GC to reclaim circular references. As well, it's certainly possible to use a mortalize scheme for simple escape analysis to catch the majority of cases where you want timely destruction; most objects tend to have reference counts of zero or one.

Re:It's easy to get it wrong

petdance on 2010-06-24T15:06:55

What you're missing from this analysis

Using the word "analysis" here gives far too much credit. It is not "analysis" to say "Can't you just do a new GC?"

Wall obsession?

Aristotle on 2010-06-24T13:32:39

This is the sort of things that we lose by allowing Wall and his minions to have his way.

Uhm, the development effort for Perl 5 never ceased (although it bled momentum for a time for a long list of disparate reason), nor has Larry been involved in a very long time. In fact there is something of a schism and sometimes outright hostility between the 5 and 6 communities. It’s a convenient to identify a corrupt leader to project all problems onto, but it has little to do with reality.

Re:Wall obsession?

sigzero on 2010-06-24T23:45:15

I did not know there was outright hostility. Why would that be?

I am ignoring the original post by "ank" as tripe.

Re:Wall obsession?

Aristotle on 2010-06-25T02:11:49

Not these days so much, and I’m hoping it’s all in the past at this point.