ios - Errors autoreleasing objects just after their creation -
I am starting to investigate iOS development and I have some doubts about the release of those items for which I No reference cached. I took a look at the question "Is it possible to release an indicator without any object?" Where the autoregee message has been suggested to send immediately after its creation, and so I tried to do this in the following section of the code:
int main (int argc, char * argv []} {NSAutoreleasePool * pool = [[NSAUTOriyReppul Alok] Init]; NSURLResponse * response = zero; NSError * Error = Zero; NSDT * Data; Data = [synchronous request to send NSRR connection: [[NSRR request request with url: [[NSUr URL with string: @ "http://www.google.it"] Autorelage]] Autoreques] Returning Response: And Action Error: And Addition ; [Write data file: @ "/ tmp / test.html" atom: NO]; [Data release]; [Pool drain]; Return 0; } I can not try to execute the program in XCode yet, but I am compiling it under Linux and the autorovous message segmentation error sent to NSWRest object (I think It is not that the message is due to its own, but due to the autorescence message the pool is released to release the object). What is wrong with the Autoreview message, which I sent to the NSURLRequest object?
I think if request is requested for a class method like the dock request. With the argument that it "creates and returns a URL request" means that I use the object When I finish it, am I wrong? I should understand the rules of this memory management very well and before proceeding with it. I hope my questions are not stupid ;-)
Uh, just one last question: should I leave it also error and data items come back by synchrounous request?
Thanks in advance for any help!
+ requestWithURL: (and other) methods are already autocorrect Objects return, so you should not send them to another autoerior. Over-release additional autorel objects in your code and make app crashes.
To know the rule of thumb, whether you have to release something - a release is required when you create an object using that object in which the 'alloc', 'new', 'copy 'All standard APIs follow this rule and you should follow it during the development of your methods.
Then the correct code will be:
int main (int argc, char * argv []) {NSAutoreleasePool * pool = [[NSAUTOrepual Alok] Init]; NSURLResponse * response = zero; NSError * Error = Zero; NSDT * Data; Data = [Send NSRR Connection Synchronous Source: [NSRR Request Request with url: [NSWR URLWithString: @ "http://www.google.it"] Returning Response: And Response Error: & amp; Error]; [Write data file: @ "/ tmp / test.html" atom: NO]; [Pool drain]; Return 0; } PS Neither data and error objects should be released for the above reasons.
Comments
Post a Comment