> 30.03.2011 21:45, Vlad Khorsun wrote:
> 
>>> What would do a detach/commit/etc in an object when refcount>  1?
>>
>>      Call corresponding method of real object. And not touch refcount.
>>
>>> What would do a detach/commit/etc in an object when refcount = 1?
>>
>>      Same as above.
> 
> Sorry for ignorance, but why refcount is not decremented in these cases? 

    To protect us from the more then one call of detach() for the same 
instance. 
Example :

IAttachment *att = provider->attach(...);
doSomething(att);
att->detach();

doSomething(IAttachment *att)
{
  if (something very bad happens)        // this could be really at the few 
levels 
    att->detach();                                // deeper at whole call stack
}

    Well, we can decrement refcount in detach() on success only, but it sounds 
as (not necessary) complication of reference counting policy.

> I mean, what is the point in requiring an extra release() call if the 
> user has explicitly stated that he no longer needs an object. Note that 
> we don't require an explicit addRef() call when the object gets created.

    I understand your concerns. BTW, changing way to create objects from 

IAttachment *attach(...)

by 

void attach(..., **IAttachment)

allows us to use smart pointers and make no additional call of release() :

{
    smart_ptr<IAttachment> att = NULL;
    provider->attach(..., att.refPtr());        // refcnt == 1 here !
    doSomething(att);
    att->detach();                        // refcnt == 1
}                                            // ~smart_ptr will decrement refcnt

Regards,
Vlad

------------------------------------------------------------------------------
Xperia(TM) PLAY
It's a major breakthrough. An authentic gaming
smartphone on the nation's most reliable network.
And it wants your games.
http://p.sf.net/sfu/verizon-sfdev
Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel

Reply via email to