I need help.
I’m creating some ASIHTTPRequests, but it’s crashing sometimes.
I’ve found, that it due to initialization.
I must use code like this:
ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:myURL];
{my code}
[request release];
or this:
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:myURL];
Can you tell difference?
PS:
I have ten requests, which starts in one time, and one, which starts before.
The first one is a standard allocation, while the second implies the class method that returns an
autoreleased object.Assuming that you have this code inside a controller (or viewController), the
requestobject presumably gets deallocated when the method ends.So you need to keep a reference to that object inside your controller, so that it doesn’t get deallocated.
So, your interface definition:
And then the implementation
By the way, if you have more than one request, it would be better to use a network queue, so you keep a reference to the queue instead to the various single requests.
See this gist, which uses the
ASINetworkQueue.