I'm trying to understand how reference counting works, so I disabled ARC and wrote a simple class: (Foo.h is not pasted as it is unmodified)
Foo.m
@implementation Foo
- (instancetype)init
{
NSLog(@"Init object");
return [super init];
}
- (void)dealloc
{
NSLog(@"Dealloc object");
[super dealloc];
}
@end
Main.m
#import <Foundation/Foundation.h>
#import "Foo.h"
int main(int argc, const char * argv[]) {
Foo *obj = [[Foo alloc] init];
obj = nil;
return 0;
}
Now I expect to see the dealloc object
log, because the only reference to Foo
object is gone, but the only message I get is the init object
.
Why don't I see it? Isn't the object released when I assign obj = nil
?