Find in this group all groups
Unknown more information…

o : 12 December 2005 • 8:03AM -0500

destructor called twice on inline function object?
by Eric Miller


Apologies if this isn't the right place to ask this. I'm new to the
lists here. Also apologies if I'm just forgetting something obvious.

I'm using Obj-C++ with whatever specific compiler is running under
XCode on Tiger 10.4.3.

I'm passing a function object as predicate to stl's find_if. The
function object's constructor is being called once as expected upon
entering find_if. On return, the destructor is being invoked *twice*:
seemingly once when losing scope in find_if and once after find_if
returns ... it's hard to be precise because XCode/gdb is not
respecting breakpoints inside my function object's xtors. But that's a
different issue (though maybe related somehow?).

This is, needless to say, detrimental to my program's stability. Any
ideas about this would be greatly appreciated. I can work around it,
of course, but as far as I know, this shouldn't be happening. But ...
surely I'm just forgetting something elementary?

Many thanks!
Eric Miller

The relevant code's pretty short, so I'll paste it in:

// --------------------- function object interface, an inner class to "VizNode"

class hasGUID : public std::unary_function< VizNode*, bool >
hasGUID( NSString* iGUID );
result_type operator() ( argument_type n );
NSString* mGUID;

// --------------------- defintion
VizNode::hasGUID::hasGUID( NSString* iGUID )
: mGUID( [ iGUID retain ] )
[ mGUID release ];

VizNode::hasGUID::operator() ( argument_type n )
return [ mGUID isEqualToString:n->getGUID() ];

// --------------------- the call that causes TWO invocations of the destructor,
// --------------------- causing net decrement of the retain count on
the passed string.

std::vector< VizNode* >::iterator it;
it = std::find_if( vizNodes->begin(),
VizNode::hasGUID( [ oldNode valueForKey:@"guid" ] ) );
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list      (Objc-language@list...)
Help/Unsubscribe/Update your Subscription:

This email sent to subscriber@open...

Bookmark with:

Delicious   Digg   reddit   Facebook   StumbleUpon

Related Messages

opensubscriber is not affiliated with the authors of this message nor responsible for its content.