I am making a call to a database. After my call, I've found leaks in NSString. Anybody have a solution to remove it?
NSString *pic = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectStatement, 5)];
In above code, I found 90% leaks. I just read data from database.
please explain the question well else others can't identify your exact problem.
I think you are you are assigning the value of [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectStatement, 5)]; to your class object property.
You can release the assigned class string property in the corresponding class dealloc method.Also set it nil.
Example:
if you are doing
the class structure will like
.m file will be
Check it.. this structure will not show memory leak.
Are you calling
sqlite3_finalize()
to free up memory?If you are doing it, then the leak is possibly with the
NSString
, but we would need to know what you do with it (it is autoreleased, so you don't need torelease
it, but you could be retaining it somewhere else in your code).Furthermore, it is not safe to pass
sqlite3_column_text
directly intostringWithUTF8String
, since in case it returnsnil
, your application will crash.You might also consider using fMDB, an ObjC wrapper around sqlite3. Find it here.