Re: Trying to intentionally create a memory leak
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