Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trying to intentionally create a memory leak




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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden

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



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.