Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS - object sent autorelease too many times
    primarykey
    data
    text
    <p>I have a method that is reading some information from a sqlite db and initialising a class called Achievement. When I analyse this code I am given the feedback 'object sent autorelease too many times'. I don't really understand where I am going wrong - why is the retval object released on line 225 and not at the return statement on line 229? </p> <p>Can someone please explain where I have made a mistake in the code below and how I can fix it?</p> <p>Function Code (so answerer can easily copy/paste):</p> <pre><code>- (Achievement *)getAchievement:(int)Id </code></pre> <p>{</p> <pre><code>Achievement *retval = [[Achievement alloc] autorelease]; NSString *query = [NSString stringWithFormat:@"SELECT * FROM Achievements where ID = %d", Id]; sqlite3_stmt *statement; if (sqlite3_prepare_v2(_database, [query UTF8String], -1, &amp;statement, nil) == SQLITE_OK) { while (sqlite3_step(statement) == SQLITE_ROW) { int Id = sqlite3_column_int(statement, 0); char *name = (char *) sqlite3_column_text(statement, 1); char *title = (char *) sqlite3_column_text(statement, 2); char *description = (char *) sqlite3_column_text(statement, 3); Boolean Achieved; char *com = (char *) sqlite3_column_text(statement, 4); NSString *c1 = [[[NSString alloc] initWithUTF8String:com] autorelease]; Achieved = [c1 isEqualToString:@"1"]; NSDate *CompletedDate = (NSDate *) sqlite3_column_text(statement, 5); char *icon = (char *) sqlite3_column_text(statement, 6); int New = sqlite3_column_int(statement, 7); NSString *Title = [[[NSString alloc] initWithUTF8String:title] autorelease]; NSString *Description = [[[NSString alloc] initWithUTF8String:description] autorelease]; NSString *Name = [[[NSString alloc] initWithUTF8String:name] autorelease]; NSString *Icon = [[[NSString alloc] initWithUTF8String:icon] autorelease]; retval = [retval initDetails:Id :Name :Title: Description : Achieved : CompletedDate: Icon: New]; } sqlite3_finalize(statement); } return retval; </code></pre> <p>}</p> <p>Analysis feedback image: <img src="https://i.stack.imgur.com/lxFPb.png" alt="enter image description here"></p> <p>As always any feedback is greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload