Skip to content

Instantly share code, notes, and snippets.

@torsten
Created March 30, 2009 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torsten/87726 to your computer and use it in GitHub Desktop.
Save torsten/87726 to your computer and use it in GitHub Desktop.
Prove: [release] doesn't set a variable to nil
// gcc not_nil.m -lObjC -framework Foundation && ./a.out
#include <stdio.h>
#include <stdarg.h>
#include <Cocoa/Cocoa.h>
@interface FooClass : NSObject
{
}
@end
@implementation FooClass
- (id)init
{
if((self = [super init]))
{
printf("init, I am at 0x%x\n", self);
}
return self;
}
- (void)dealloc
{
printf("dealloc\n");
[super dealloc];
}
@end
int main (int argc, char const *argv[])
{
FooClass *obj;
printf("0x%x // random value\n", obj);
obj = [[FooClass alloc] init];
printf("0x%x // addr of the obj\n", obj);
[obj release];
printf("0x%x // still the same addr and not 0x%x (nil) "
"because you did not touch the value of obj, "
"you just called a method on it\n",
obj, nil);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment