I would like to know if calling a method in the following format is any reason for LEAKS?
[userLookupWS initWithUsername:[NSString stringWithUTF8String:(char *)sqlite3_column_text(select_system, 2)] andPassword:[NSString stringWithUTF8String:(char *)sqlite3_column_text(select_system, 3)] andURL:[NSString stringWithFormat:@"%@%@", [NSString stringWithUTF8String:(char *)sqlite3_column_text(select_system, 0)], [NSString stringWithUTF8String:(char *)sqlite3_column_text(select_system, 1)]] andSSL:[NSString stringWithUTF8String:(char *)sqlite3_column_text(select_system, 4)]];
What is the other way round to pass parameters to this method as I am getting 100% memory leak in this statement!
Regards,
Accilies
Why are you sending
initWithUsername:to an object stored in a variable? You should be passing the result of alloc there directly (userLookupWS = [[SomeClass alloc] initWithUsername:…]), and don’t ever re-initialize an existing instance.Aside from just being strange (it’s initialized already! Why are you initializing it again?), nearly all
init…methods are written for the assumption that they’ll only be called once per instance, so sending aninitWithWhatever:message to an already-initialized instance will leak everything that that instance owns.There is no good way to fix that except to simply not do that in the first place. Don’t send any
initmessage to an already-initialized instance. The easiest way to avoid this is to only send aninitmessage directly to the return value ofalloc([[SomeClass alloc] init…]).And, of course, anything
allocreturns, you have to release. The easiest way to ensure that happens is to autorelease the object immediately:[[[SomeClass alloc] init…] autorelease].