Je vous écris un cadre et j'ai un objet avec une méthode d'initialisation personnalisée:Appeler dealloc dans init?
@implementation OSDatabase
@synthesize database;
// MEM
- (void)dealloc {
sqlite3_close(database);
[super dealloc];
}
// INIT
- (id)initWithDatabasePath:(NSString *)path error:(NSError **)error {
if (self = [super init]) {
if (!sqlite3_open_v2([path UTF8String], &database, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL)) {
error = [NSError errorWithDomain:@"OSDatabaseErrorDomain" code:1 userInfo:nil];
[self dealloc];
return nil;
}
}
return self;
}
@end
Est-il sûr d'appeler dealloc
à l'intérieur d'une méthode init
si une erreur occoured? Je ne suis pas sûr à ce sujet et la gestion de la mémoire est l'une des choses les plus importantes dans ma vie.
Merci.
Qu'en est-il de 'while ([self retainCount]! = 0) {[self release];}'? –
@Koning Baard: ** Non! ** C'est tout aussi mauvais. Je vais éditer ma réponse pour expliquer pourquoi. – JeremyP
"Pile d'excréments" rend à peine justice à quel point c'est ...:) – bbum