Note that there are some explanatory texts on larger screens.

plurals
  1. POanalyzer and autorelease issues with custom objects
    primarykey
    data
    text
    <p>I have a class that manages the database queries for my project and I'm having some issues with memory management and the <code>[return autorelease]</code>part of the code. I don't know how to return an object to the calling function but it uses it afterwards. The code is this:</p> <pre><code>-(Hexagram *)getHexagramforId:(NSInteger)hexagramNumber{ Hexagram *current; if (init_statement == nil) { const char * sql = "SELECT * FROM HEXNUMBER where _id =?"; if (sqlite3_prepare_v2(database, sql, -1, &amp;init_statement, NULL) != SQLITE_OK) { NSAssert1(0, @"Error:failed to prepare argument with message %s", sqlite3_errmsg(database)); } sqlite3_bind_int(init_statement, 1, hexagramNumber); if (sqlite3_step(init_statement) == SQLITE_ROW) { current = [[Hexagram alloc]initWithId:hexagramNumber Title:[NSString stringWithUTF8String:(char*)sqlite3_column_text(init_statement, HEX_TITLE)] LongText:[NSString stringWithUTF8String:(char*)sqlite3_column_text(init_statement, HEX_TEXT)]ShortText:nil InternalColor:sqlite3_column_int(init_statement, INTERNAL_COLOR) ExternalColor:sqlite3_column_int(init_statement, EXTERNAL_COLOR)]; }else{ NSAssert1(0, @"Database is corrupt, error %s", sqlite3_errmsg(database)); } sqlite3_reset(init_statement); sqlite3_close(database); init_statement = nil; return current; } return nil; </code></pre> <p>}</p> <p>So what happens is in the analyzer it says that the object current hexagram is leaked, but if I return it with an autorelease it crashes. I want to support iOS &lt; 5 so I don't want to use ARC but so far I don't know how to return this object and not get this error in the static analyzer. Any help please?</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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