• 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: Am I overreleasing something?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Am I overreleasing something?


  • Subject: Re: Am I overreleasing something?
  • From: Glen Simmons <email@hidden>
  • Date: Fri, 10 Jun 2005 09:44:07 -0500

On Jun 10, 2005, at 9:17 AM, Theodore H. Smith wrote:

I suppose this means that I'm overreleasing something, right?

If so, what's a good technique to track this down (Apart from stepping through every line of code, which I always do)? Is there someway to make the release pool release early, so that I can narrow down the bug to a specific area of my code?



No, but you can find out what kind of object it is that's getting over-released. Check out NSZombieEnabled


http://developer.apple.com/technotes/tn2004/tn2124.html#SECFOUNDATION


I suppose the other way is to avoid using autorelease, entirely, and use release whereever possible. At least that way I'll get my errors as soon as possible.

Well, there's no way to avoid using autorelease entirely. The simple act of creating a standard Cocoa object may create one or more autoreleased objects underneath. So even if you only ever use alloc/ init and release, there are objects being autoreleased anyway. Also, there will be lots of times when you need to return an autoreleased object.


The other thing I would point out is that autorelease is a very useful tool and you would be really limiting yourself if you tried to do without it. Compare:

    NSString *foo = [NSString stringWithFormat:@"%d", myInt];
    <more code>
    // foo was autoreleased, so no need to worry about releasing it.

to

NSString *foo = [[NSString alloc] initWithFormat:@"%d", myInt];
<more code>
// Sometime later, you have to remember to release foo or you'll have a memory leak.


So, instead of trying to avoid it, learn how to use it. You'll be a better programmer for it.

Glen
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Am I overreleasing something?
      • From: Ondra Cada <email@hidden>
References: 
 >Am I overreleasing something? (From: "Theodore H. Smith" <email@hidden>)
 >Re: Am I overreleasing something? (From: Glen Simmons <email@hidden>)
 >Re: Am I overreleasing something? (From: "Theodore H. Smith" <email@hidden>)

  • Prev by Date: Re: xcode keeps crashing when i compile
  • Next by Date: Re: Newbie-Question: Sorting Arrays
  • Previous by thread: Re: Am I overreleasing something?
  • Next by thread: Re: Am I overreleasing something?
  • Index(es):
    • Date
    • Thread