POV-Ray : Newsgroups : povray.off-topic : Programming design question, related to GC : Re: Programming design question, related to GC Server Time
4 Nov 2024 17:36:54 EST (-0500)
  Re: Programming design question, related to GC  
From: Darren New
Date: 12 Apr 2008 14:30:50
Message: <4800ffda$1@news.povray.org>
Warp wrote:
>   Can you mention some popular GC's languages where it's possible to
> implement reference-counting of objects? 

Hmmm. Well, of course you can implement the reference counting 
everywhere you assign or overwrite or dispose of a pointer of that type, 
but that's not what you mean. I can't think of any languages offhand 
that specify reference counting is built in but also allow you to do 
actions when pointers enter and leave scope, like you can in C++.

Maybe Objective-C? That's the only "popular" one I know of but don't 
know well enough to answer the question.

Of course, if you make a mistake anywhere in the reference counting 
doing this, you're going to have a memory leak just like any other 
manual memory management.

Weak references are the solution to this sort of thing, which also 
brings the benefit of being able to add the listener to more than one 
engine, for example. I don't think it's possible to reasonably implement 
weak references with a library without compiler support, at least in 
most GCed languages (which don't give you access to the internal data 
they use to do the GC).

Now, COP (concurrency-oriented programming) is a bit different. In 
languages where your objects tend to be "active", i.e., not only have 
code but have a stack and a program counter, the connections between 
objects are often tracable - you can tell when another process has 
connected to you, and when it has disconnected, and how many are 
connected. Some languages can, some can't, depending on whether they 
implement the connections as connections between processes or 
connections between ports/mailboxes.

But no, C++ is definitely more powerful in this respect. It would be 
nice to see a language that would invoke a finalize method any time it 
can statically deduce that some object is going to disappear at some 
particular point, or to let you mark some particular class as 
reference-counted, so as long as you don't get into circular references, 
it can get collected deterministically (and trigger finalizers).

-- 
   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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.