On Sep 8, 2012, at 8:00 PM, koko wrote:
> the m_xmlParserDelegate object is instanced in IB
Not a fan of instantiating objects in IB. Way too easy to get gigantic nibs
going which ain't right.
> - (void)startMessageParse:(void*)msgStart end:(void*)msgEnd
> {
> NSInteger length = msgEnd-msgStart+1;
> if(length > 0 && length < 4096)
"the length check is arbitrary as I found without it I could get lengths that
caused the dataWithBYtes to blow up"
Yeeeeaahh… your problem is elsewhere. dataWithBytes can certainly work with
more than 4KB.
> {
> NSData *data = [NSData dataWithBytes:msgStart length:length];
> if(data)
It's not going to fail.
> NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:data];
> [xmlParser setDelegate:m_xmlParserDelegate];
> [xmlParser parse];
> [data release];
Wrong. data was not alloc'd, create'd, copy'd, and was not retained by self so
this an overrelease.
> [xmlParser release];
Correct.
You're better of putting the NSData creation outside of this method where
details of msgStart/msgEnd are better known, which would leave you with:
- (void)parseData:(NSData *)data
{
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:data];
[xmlParser setDelegate:m_xmlParserDelegate];
[xmlParser parse];
[xmlParser release];
}
…but then one has to wonder why you need this method in this particular object.
It's a bit awkward. I don't know what your delegate does exactly, particularly
handling the results, but I would lean towards handing the data to the delegate
object and telling it to parse it, rather than creating a parser here and
setting the delegate.
--
Seth Willits
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]