• 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
alloc/release confusion
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

alloc/release confusion


  • Subject: alloc/release confusion
  • From: Boon Chew <email@hidden>
  • Date: Fri, 13 Feb 2009 15:02:35 -0800 (PST)

Hi all,

I am very new to Cocoa programming (but have programmed in C/C++ before) and there is one thing I don't understand with alloc and release.  Sometimes I see code that alloc an object and release it within the same method, even though it's clear that the object is still live and well.

For example:

-(IBAction)onButtonPressed
{
  UIAlertView *alert = [[UIAlertView alloc] initWithTitle...];
  [alert show];
  [alert release];
}

Why is the code decrementing the ref count even though the alert window is still up?

Also, how do you know when you are decrementing ref count too soon? How do you know which object method you call might increase the ref count of the object in question?

Thanks!

- boon







_______________________________________________

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: alloc/release confusion
      • From: Bryan Henry <email@hidden>
    • Re: alloc/release confusion
      • From: Kenny Leung <email@hidden>
  • Prev by Date: Re: NSRunLoop / CFRunLoop
  • Next by Date: Re: alloc/release confusion
  • Previous by thread: Re: NSTableView crash when selected.
  • Next by thread: Re: alloc/release confusion
  • Index(es):
    • Date
    • Thread