Re: Lock-free reference counting



Juha Nieminen <nospam@xxxxxxxxxxxxxx> wrote:

Again, false. "a" is very well alive after the call to f(), and it
has internally a pointer to the allocated object. A GC won't destroy
that object as long as "a" is alive and well.

In fact it needn't be. In the absence of C++ destructor semantics, the
compiler would be free to remove any reference to `a' from registers (or
anywhere else) immediately, and indeed this may well be sensible, in
order to recycle the register for something more valuable.

As a practical matter, I've had a (Boehm--Demers--Weiser) collector free
up objects `prematurely' -- i.e., highlighting a bug where the
programmer failed to keep a reference alive for long enough.

But there's no fundamental reason why a GC /has/ to collect stuff early.
The primary abstraction that a GC provides is an illusion of unbounded
storage, and exactly how it decides to achieve that is its business.
(Of course, such characteristics may lead one to choose a particular GC
implementation or technique over others; I mean to say only that they're
not fundamental to the idea of GC.)

It's precisely because a GC has absolutely no notion of what the code
is doing that it can *not* collect that object. It sees a pointer
pointing to the object,

Why is there necessarily a pointer still?

Yes, and that's exactly why both PHP and Apple's Objective-C (eg. on
the iPhone) use reference counting for memory management?

Trying to argue that something is sensible because PHP does it is not
especially convincing! GCC's Objective-C implementation uses the BDW
collector, by the way.

-- [mdw]
.



Relevant Pages

  • Re: Question on LSP
    ... Sure, the developer must keep track of which type has been assigned to each pointer to manage complexity in creating the design, which is why the 'T' is in T*. ... Subtyping is a relation which does not ... Those object types are completely orthogonal to the semantics of being an object reference. ... aggregate references, is the aggregate of referenced objects or target ...
    (comp.object)
  • Re: Question on LSP
    ... Because construction paradigms have different goals. ... But that has nothing to do with what a pointer type ... But that does not mean that the semantics of an object reference is ... aggregate references, is the aggregate of referenced objects or target ...
    (comp.object)
  • Re: Modifying Class Object
    ... Before I start, note we're talking about semantics, not ... For example, as I used as reference in my first posting, the Java language spec. ... A pointer stores a reference to something. ...
    (comp.lang.python)
  • Re: Question on LSP
    ... equivalent addresses in the same context. ... Note that the language allows us to use a name like 'T' on the reference as a mnemonic so that the developer can keep track of what is happening with the indirection. ... Modern languages have proper pointer types. ...
    (comp.object)
  • Re: Nothing Keyword Destories Objects rather than just resetting the variable to an empty variable
    ... there is no difference between using ByVal or ByRef. ... as the C1 pointer was the sole reference to the class object. ... Yes, an object variable is a pointer to an object, but that is the only ... the keyword "NOTHING" should only destroy the ...
    (microsoft.public.excel.programming)