Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7783713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:55:07+00:00 2026-06-01T19:55:07+00:00

I created DownloadAndParseBook class. It will not autorelesed before it gеt any data or

  • 0

I created DownloadAndParseBook class. It will not autorelesed before it gеt any data or network error.

I used [self release], [self retain]. Is it good approach to use [self release], [self retain]? Is DownloadAndParseBook contain any potential bugs?

@implementation GetBooks

-(void) books
{ 
 for(int i =0; i<10; i++)
 {
   DownloadAndParseBook *downloadAndParseBook =
        [[[DownloadAndParseBook alloc] init]autorelease];
   [downloadAndParseBook startLoadingBook];
 }
}
@end


@implementation DownloadAndParseBook

- (id)initWithAbook:(int)bookID 
{
 if(self = [super init])
 { 
    [self retain];        
 }
 return self;
}

- (void)startLoadingBook
{
 [NSURLConnection connectionWithRequest:request delegate:self];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
  [self release];    
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
 [self saveResultToDatabase];
 [self release];
}


@end 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:55:09+00:00Added an answer on June 1, 2026 at 7:55 pm

    Self retaining is very occasionally an appropriate pattern. It’s rare, but sometimes in certain kinds of multi-threaded code its important to make sure that you don’t vanish in the middle of processing something. That said, this is not one of those times. I’m having trouble imagining a case where your current approach would be helpful. If someone creates your object and then never calls startLoadingBook, then it leaks. If someone calls startLoadingBook, then your object is retained anyway, because NSURLConnection retains its delegate until it finishes.

    That said, I believe much of your problem is coming from the fact that your object model is wrong. Neither GetBooks nor DownloadAndParseBook make sense as classes. What you likely mean is BookManager (something to hold all the books) and BookDownloadController (something to manage the downloading of a single book). The BookManager should keep track of all the current BookDownloadControllers (in an NSSet or NSArray ivar). Each BookDownloadController should keep track of its NSURLConnection (in an ivar). You should not just create connections and have them “hang on themselves” (i.e. self-retain). This feels convenient, but it makes the code very hard to deal with later. You have no way to control how many connections you’re making. You have no way to cancel connections. It becomes a mess really quickly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Created .NET WCF service, tested it - works. Generated schemas from Data and service
Created Private Key & Self signed certficate in a Key Store keytool -genkey -alias
I created a batch file to run SqlMetal and generate Linq2Sql data classes, check
I created number of migrations starting with a definition for a Posts table. class
I created a web control, and it needs some data from its parent page.
I created a file in \res\layout named contactlist.xml But it is not recognized in
I created an IB file and linked it to MyAVController class. But then I
Created a AlertDialog that is used to prompting the user to enter a keyword.
I created the following simple class in my code and I get TObject is
I created a class extending Application to have global variables in my app. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.