Re: NSXMLParser frees itself on error?

2009-05-08 Thread Marcel Weiher
On May 8, 2009, at 6:50 , Michael Ash wrote: Begin forwarded message: From: Marcel Weiher Date: May 7, 2009 10:05:29 PDT And yes, the code that I use explicitly runs the runloop, and it is the code that runs the runloop that both allocates the NSURLConnection and then cleans up after

Re: NSXMLParser frees itself on error?

2009-05-08 Thread Michael Ash
On Fri, May 8, 2009 at 1:43 AM, Marcel Weiher wrote: > > On May 7, 2009, at 21:12 , Michael Ash wrote: > >> On Thu, May 7, 2009 at 11:53 PM, Marcel Weiher >> wrote: >>> >>> On May 7, 2009, at 17:29 , Jeff Johnson wrote: >>> On May 7, 2009, at 6:00 PM, Marcel Weiher wrote: >> That's

Re: NSXMLParser frees itself on error?

2009-05-07 Thread Marcel Weiher
On May 7, 2009, at 21:12 , Michael Ash wrote: On Thu, May 7, 2009 at 11:53 PM, Marcel Weiher > wrote: On May 7, 2009, at 17:29 , Jeff Johnson wrote: On May 7, 2009, at 6:00 PM, Marcel Weiher wrote: That's not what I was talking about. I was talking about the possibility that the 'owned' c

Re: NSXMLParser frees itself on error?

2009-05-07 Thread Michael Ash
On Thu, May 7, 2009 at 11:53 PM, Marcel Weiher wrote: > > On May 7, 2009, at 17:29 , Jeff Johnson wrote: > >> On May 7, 2009, at 6:00 PM, Marcel Weiher wrote: >> That's not what I was talking about. I was talking about the possibility that the 'owned' caller manually runs the run loop ri

Re: NSXMLParser frees itself on error?

2009-05-07 Thread Marcel Weiher
On May 7, 2009, at 17:29 , Jeff Johnson wrote: On May 7, 2009, at 6:00 PM, Marcel Weiher wrote: That's not what I was talking about. I was talking about the possibility that the 'owned' caller manually runs the run loop right after it calls the delegate callback, so any performSelector:

Re: NSXMLParser frees itself on error?

2009-05-07 Thread Jeff Johnson
On May 7, 2009, at 6:00 PM, Marcel Weiher wrote: And yes, the code that I use explicitly runs the runloop, and it is the code that runs the runloop that both allocates the NSURLConnection and then cleans up after it checks the flag. Perfectly safe, perfectly synchronous. That's not what

Re: NSXMLParser frees itself on error?

2009-05-07 Thread Marcel Weiher
On May 7, 2009, at 10:39 , Jeff Johnson wrote: Actually, you were initially claiming that there was such a guarantee, and misquoting the docs to 'prove' your point. The memory management docs tell you what you should do, but nothing in Objective-C or Cocoa requires you to follow them. Wel

Re: NSXMLParser frees itself on error?

2009-05-07 Thread Jeff Johnson
On May 7, 2009, at 12:05 PM, Marcel Weiher wrote: On May 7, 2009, at 9:43 , Jeff Johnson wrote: You misunderstand my argument. I'm not claiming that autorelease provides some magical guarantee. Actually, you were initially claiming that there was such a guarantee, and misquoting the docs

Re: NSXMLParser frees itself on error?

2009-05-07 Thread Marcel Weiher
On May 7, 2009, at 9:43 , Jeff Johnson wrote: You misunderstand my argument. I'm not claiming that autorelease provides some magical guarantee. Actually, you were initially claiming that there was such a guarantee, and misquoting the docs to 'prove' your point. I'm claiming that you oug

Re: NSXMLParser frees itself on error?

2009-05-07 Thread Jeff Johnson
On May 7, 2009, at 11:18 AM, Marcel Weiher wrote: On May 7, 2009, at 8:37 , Jeff Johnson wrote: No, autorelease can be used to ensure that the returned object is valid within the scope of the caller, You can *try* to use it to ensure that, but as we have found out, you have no way of actu

Re: NSXMLParser frees itself on error?

2009-05-07 Thread Marcel Weiher
On May 7, 2009, at 8:37 , Jeff Johnson wrote: On May 7, 2009, at 2:38 AM, Marcel Weiher wrote: EXACTLY. Autorelease allows ownership transfer from called methods to occur without thrusting ownership on those that don't want it. That's one use, anyway. No. That is what you need autor

Re: NSXMLParser frees itself on error?

2009-05-07 Thread Jeff Johnson
On May 7, 2009, at 2:38 AM, Marcel Weiher wrote: EXACTLY. Autorelease allows ownership transfer from called methods to occur without thrusting ownership on those that don't want it. That's one use, anyway. No. That is what you need autorelease for. Anything else is fluff. No, autore

Re: NSXMLParser frees itself on error?

2009-05-07 Thread Marcel Weiher
On May 6, 2009, at 23:56 , Jeff Johnson wrote: On May 7, 2009, at 12:27 AM, Marcel Weiher wrote: OK, quiz time: the reason for NSMutableString to relinquish ownership is to (a) release the object (b) allow someone else to take ownership? Answer: always (a), sometimes (b), and sometimes

Re: NSXMLParser frees itself on error?

2009-05-07 Thread Jeff Johnson
On May 7, 2009, at 12:27 AM, Marcel Weiher wrote: In fact, NSXMLParser very likely *should* maintain autorelease pools, because its clients can't safely do this and there is quite a potential for growing the heap during XML parsing. "One technique for dealing with these generated objects i

Re: NSXMLParser frees itself on error?

2009-05-06 Thread Jeff Johnson
On May 7, 2009, at 12:27 AM, Marcel Weiher wrote: OK, quiz time: the reason for NSMutableString to relinquish ownership is to (a) release the object (b) allow someone else to take ownership? Answer: always (a), sometimes (b), and sometimes (c). EXACTLY. Autorelease allows ownership trans

Re: NSXMLParser frees itself on error?

2009-05-06 Thread Marcel Weiher
On May 6, 2009, at 21:34 , Jeff Johnson wrote: Ownership 'transfer' is rare. If you call +alloc or -copy, for example, ownership is transferred to the caller. Otherwise, there's no such thing. The fact that you think this is a testament to how well - autorelease works :-) How about +[N

Re: NSXMLParser frees itself on error?

2009-05-06 Thread Jeff Johnson
On May 6, 2009, at 9:38 PM, Marcel Weiher wrote: On May 6, 2009, at 18:45 , Jeff Johnson wrote: I think you misunderstand the problem that autorelease is trying to solve, which is to allow ownership transfer from a callee back to its caller, not to just simply delay a release until "later".

Re: NSXMLParser frees itself on error?

2009-05-06 Thread Stephen J. Butler
On Wed, May 6, 2009 at 5:49 PM, Jeff Johnson wrote: > I find this idea somewhat suspect. It seems to undermine the basic function > of the autorelease call, which is delay a release until later. > > The reasoning here could be taken to the point of absurdity. This is because > a 'callee' (self, th

Re: NSXMLParser frees itself on error?

2009-05-06 Thread Marcel Weiher
On May 6, 2009, at 18:45 , Jeff Johnson wrote: I think you misunderstand the problem that autorelease is trying to solve, which is to allow ownership transfer from a callee back to its caller, not to just simply delay a release until "later". Ownership 'transfer' is rare. If you call +al

Re: NSXMLParser frees itself on error?

2009-05-06 Thread Jeff Johnson
On May 6, 2009, at 7:57 PM, Marcel Weiher wrote: On May 6, 2009, at 15:49 , Jeff Johnson wrote: I still maintain that it's never safe to release/autorelease an object from inside one of it's delegate calls. If it works at all, you're implicitly relying on an implementation detail that's subj

Re: NSXMLParser frees itself on error?

2009-05-06 Thread Marcel Weiher
On May 6, 2009, at 15:49 , Jeff Johnson wrote: I still maintain that it's never safe to release/autorelease an object from inside one of it's delegate calls. If it works at all, you're implicitly relying on an implementation detail that's subject to change. I find this idea somewhat suspe

Re: NSXMLParser frees itself on error?

2009-05-06 Thread Jeff Johnson
On May 4, 2009, at 1:31 PM, Stephen J. Butler wrote: On Fri, May 1, 2009 at 11:18 AM, Jesper Storm Bache wrote: I have not used NSXMLParser, but as far as I can tell from your email, cleanupShowParsing is called in response to a call to the parser delegate. In that case, you should not rel

Re: NSXMLParser frees itself on error?

2009-05-04 Thread Kyle Sluder
On Mon, May 4, 2009 at 2:31 PM, Stephen J. Butler wrote: > I still maintain that it's never safe to release/autorelease an object > from inside one of it's delegate calls. If it works at all, you're > implicitly relying on an implementation detail that's subject to > change. Sometimes you do have

Re: NSXMLParser frees itself on error?

2009-05-04 Thread Jesper Storm Bache
Hi Stephen, I agree with you, deleting the owner of a delegate from a delegate callback (either directly, or though an auto-release pool) is not a good practice. Lifetime should be managed on the outside of the parser (after "parse" returns). Jesper On May 4, 2009, at 11:31 AM, Stephen J

Re: NSXMLParser frees itself on error?

2009-05-04 Thread Kyle Sluder
On Mon, May 4, 2009 at 5:05 PM, Sean McBride wrote: > Actually, they should call [super dealloc] not [self release], see: You're right. Brain fart. --Kyle Sluder ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin request

Re: NSXMLParser frees itself on error?

2009-05-04 Thread Sean McBride
On 5/3/09 5:38 PM, Kyle Sluder said: >Initializers must call -[self release] in case of an error. This >means that in response to an error that occurs as part of >initialization, you must not release that object. Actually, they should call [super dealloc] not [self release], see:

Re: NSXMLParser frees itself on error?

2009-05-04 Thread Ed Wynne
On May 3, 2009, at 5:38 PM, Kyle Sluder wrote: Initializers must call -[self release] in case of an error. This means that in response to an error that occurs as part of initialization, you must not release that object. Initializers that call -[self release], for any reason, had also bette

Re: NSXMLParser frees itself on error?

2009-05-04 Thread Mike Manzano
I tried doing an autorelease from the delegate and that seemed to work fine. Still not sure if that's entirely correct. I was under the impression that -parse was asynchronous, so therefore I couldn't call release right after it, but if it is indeed synchronous, I'll just stick the release

Re: NSXMLParser frees itself on error?

2009-05-04 Thread Stephen J. Butler
On Fri, May 1, 2009 at 11:18 AM, Jesper Storm Bache wrote: > I have not used NSXMLParser, but as far as I can tell from your email, > cleanupShowParsing is called in response to a call to the parser delegate. > In that case, you should not release the parser (because it is calling your > delegate

Re: NSXMLParser frees itself on error?

2009-05-04 Thread Kyle Sluder
Initializers must call -[self release] in case of an error. This means that in response to an error that occurs as part of initialization, you must not release that object. --Kyle Sluder ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do

Re: NSXMLParser frees itself on error?

2009-05-04 Thread Fritz Anderson
On 1 May 2009, at 1:59 AM, Mike Manzano wrote: My question is it the case that NSXMLParser frees itself if it encounters an error, but does NOT free itself on a successful parse of a document? When parser:parseErrorOccurred: is sent, the parser is still running. You can't release it in th

Re: NSXMLParser frees itself on error?

2009-05-04 Thread Jesper Storm Bache
I have not used NSXMLParser, but as far as I can tell from your email, cleanupShowParsing is called in response to a call to the parser delegate. In that case, you should not release the parser (because it is calling your delegate and is on the stack). Try using autorelease instead. Jesper

Re: NSXMLParser frees itself on error?

2009-05-04 Thread Keary Suska
On May 1, 2009, at 12:59 AM, Mike Manzano wrote: I have an NSXMLParser doing parsing the contents of a URL. It is allocated like this: _showsParser = [[NSXMLParser alloc] initWithContentsOfURL:url]; Given a good URL to a parsable XML document, its parserDidEndDocument: method calls

Re: NSXMLParser frees itself on error?

2009-05-04 Thread Stephen J. Butler
On Fri, May 1, 2009 at 1:59 AM, Mike Manzano wrote: > Note that the parser is aborted and released in here. This seems to work > just fine, multiple times, with no problems. However, if I give it a URL to > non-XML data (should be a 404 page somewhere), it calls > parser:parseErrorOccurred: as exp

NSXMLParser frees itself on error?

2009-05-01 Thread Mike Manzano
Hi Folks, I have an NSXMLParser doing parsing the contents of a URL. It is allocated like this: _showsParser = [[NSXMLParser alloc] initWithContentsOfURL:url]; Given a good URL to a parsable XML document, its parserDidEndDocument: method calls this method: - (void) cleanupShowPar