Lefora Free Forum
login join
Loading
1090 views

self = [super init]; // memory leak?

Page 1
1–3
novice - founder
14 posts

Can anyone explain why this is not a memory leak?

@implementation MyDocument

- (id)init
{
self = [super init]; // memory leak?
if (self)
{

// Add your subclass-specific initialization here.
// If an error occurs here, send a [self release] message and return nil.

}
return self;
}

// rest of auto-generated coded deleted for brevity

@end

rookie - member
3 posts

In your code I do not see any instantiation like this [[MyDocument alloc] init]. Therefor nothing is created and there can not be a memory leak. Hope this helps?
Memory leaks occure if you don't release a instance. releasing instances is done like so:
MyDocument * aDocument = [[MyDocument alloc] init];
 
// Do something with aDocument.
 
// Release aDocument.
[aDocument release].

?
63 posts

No leaks there. The [self] is not yet init'ed!

__________________
kompilesoft

come and see my website! it's real cool reviews
Page 1
1–3

Locked Topic


You must be a member to post in this forum

Join Now!