here it's another newbie question.
I want to call ASIHTTPRequest from an external class (because I already use it in my main class) and I do something like this:
ASIHTTPNSFabExt *nRequest = [[ASIHTTPNSFabExt alloc]init];
nRequest.URL = @"http://something";
nRequest.var1 = [dictionaryRecord objectForKey:@"something"];
nRequest.var2 = [dictionaryRecord objectForKey:@"something"];
[nRequest saveComment];
Where saveComment methods perform the ASIHTTPRequest tasks.
Everything is working ok except when I try to do [nRequest release] inside my main class that will generate a error inside ASIHTTPRequest methods.
Retain Count before my release is 1 and autorelease doesn't work too: I'm sure I'm missing some memory management fundamentals but 开发者_StackOverflow社区can you help me to search for the correct way to manipulate it?
Thanx in advance
Fabrizio
There's nothing obviously wrong with the code you've posted so far. The problem is possibly in your handling of the reference to the ASIHTTPRequest object within the init/dealloc methods in ASIHTTPNSFabExt.
There's nothing special you have to do with wrapping ASIHTTPRequest within another Objective-C class - just the standard make sure you're retaining/releasing the object at the right points, and not using it after you've released it.
I assume you're a clever guy, so you can almost certainly figure this out yourself using the standard techniques for debugging memory problems on iOS.
First, run with NSZombies enabled; check the console / where the app stops, you'll almost certainly find an error say "Message sent to deallocated object ", and a backtrace that shows you exactly which line of code tried to send that message.
Then you just have to figure out why that line of code is sending to a deallocated object. It'll probably be a missing "retain" or a "release" that is too early or isn't followed by assigning nil to the instance variable that was holding the object.
-- Edit --
Also worth mentioning is that you should make sure you remove the delegate from ASIHTTPRequest in your dealloc method, otherwise it might try to call your class after it has been deallocated - request.delegate = nil;
or [request clearDelegatesAndCancel];
.
精彩评论