Created
September 5, 2011 23:36
-
-
Save echristopherson/1196173 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Save as mem_leak_objc.m and compile with: | |
// gcc -o mem_leak_objc mem_leak_objc.m -lobjc -framework Foundation | |
#import <Foundation/Foundation.h> | |
#import <stdio.h> // for printf and friends | |
#import <stdarg.h> // for va_list and va_start | |
void P(NSString *fmt, ...) { | |
va_list va; | |
va_start(va, fmt); | |
NSAutoreleasePool *tempPool = [NSAutoreleasePool new]; | |
NSString *formatted = [[NSString alloc] | |
initWithFormat:fmt arguments:va]; | |
printf("%s", [formatted UTF8String]); // printf issues warning if I pass it just the string | |
[formatted release]; | |
printf("\n"); | |
[tempPool release]; | |
} | |
int main() { | |
NSAutoreleasePool *pool = [NSAutoreleasePool new]; | |
int i; | |
for(i = 0; i < 1000000000; ++ i) { | |
P(@"No longer leaking %@!", @"memory"); | |
} | |
[pool release]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment