On Tue, Oct 27, 2009 at 12:36 PM, Michael Abendroth <pfrc.yao...@googlemail.com> wrote: > #import <Foundation/Foundation.h> > > int main (int argc, const char * argv[]) { > > NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; > > for (int i = 0; i < 3; i++) { > > NSMutableString* myString = [[NSMutableString alloc] > initWithString:[[NSDate date] description]]; > > NSLog(@"%d", &myString); > > } > > [pool drain]; > > return 0; > > } > > When I run it, the program outputs the same number thrice. Why does > this happen? Shouldn't each string object be stored in a different > place in memory?
Because you're printing the address of the stack variable myString, which is the same place on the stack every time. _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com