• 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: Trying to intentionally create a memory leak
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trying to intentionally create a memory leak


  • Subject: Re: Trying to intentionally create a memory leak
  • From: Jens Alfke <email@hidden>
  • Date: Fri, 7 Mar 2008 15:00:25 -0800


On 7 Mar '08, at 2:45 PM, Jake wrote:

I have a Cocoa console application that has code that I was sure would leak - [NSNumber alloc] with no corresponding release. But when I run those tools I detect no leak.

If you're just calling literally "[NSNumber alloc]", you're probably just getting a shared placeholder object that's waiting for the -init call to create a new instance of the appropriate class. That's part of the weirdness of class-clusters. But in general it never makes sense to call +alloc without -init.


Even if you initialize the NSNumber, I know that some common values (small integers) are cached for performance reasons, so instead of allocating a new one it might just give you the shared one.

Try something like "[[NSMutableArray alloc] init]", or even good ol' "malloc(1000)".

—Jens

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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

References: 
 >Trying to intentionally create a memory leak (From: Jake <email@hidden>)

  • Prev by Date: Re: Trying to intentionally create a memory leak
  • Next by Date: Core Data MOM configurations and renaming...
  • Previous by thread: Re: Trying to intentionally create a memory leak
  • Next by thread: Core Data MOM configurations and renaming...
  • Index(es):
    • Date
    • Thread