• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Problem with allocating memory
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with allocating memory


  • Subject: Re: Problem with allocating memory
  • From: "Stephen J. Butler" <email@hidden>
  • Date: Tue, 27 Oct 2009 22:31:28 -0500

On Tue, Oct 27, 2009 at 12:36 PM, Michael Abendroth
<email@hidden> 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 (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Problem with allocating memory
      • From: Rob Keniger <email@hidden>
    • Re: Problem with allocating memory
      • From: BJ Homer <email@hidden>
References: 
 >Problem with allocating memory (From: Michael Abendroth <email@hidden>)

  • Prev by Date: Adding new Core Data objects through a form
  • Next by Date: Re: Problem with allocating memory
  • Previous by thread: Problem with allocating memory
  • Next by thread: Re: Problem with allocating memory
  • Index(es):
    • Date
    • Thread