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 >
{
public:
hasGUID( NSString* iGUID );
~hasGUID();
result_type operator() ( argument_type n );
private:
NSString* mGUID;
};
// --------------------- defintion
VizNode::hasGUID::hasGUID( NSString* iGUID )
: mGUID( [ iGUID retain ] )
{
}
VizNode::hasGUID::~hasGUID()
{
[ mGUID release ];
}
VizNode::hasGUID::result_type
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(),
vizNodes->end(),
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:
http://lists.apple.com/mailman/options/objc-language/subscriber%40opensubscriber.com
This email sent to
subscriber@open...
opensubscriber is not affiliated with the authors of this message nor responsible for its content.