Re: Can't keep from leaking memory
Re: Can't keep from leaking memory
- Subject: Re: Can't keep from leaking memory
- From: John Timmer <email@hidden>
- Date: Sat, 25 Jun 2005 09:15:23 -0400
>> OK, I'm feeling dumb tonight...
>> No matter what I try I can't keep this from leaking memory
>>
>> - (NSData*)someData {
>> NSData *someData = [[NSData alloc] initWithData:otherData];
>> if (someData == nil)
>> someData = [[NSData alloc] initWithData:someOtherData];
>> return [[someData retain] autorelease];
>> }
>>
>> Despite what I try if someData == nil during that call it will end up
>> leaking.
>> Any thoughts on how to correct this?
>
>
> You have two alloc calls there, both of which can potentially be called by
> this method. If the second one is called, the first alloc'ed instance leaks.
Actually, I'm not so sure about this - what happens when you alloc some
memory, but init returns nil - do you still have to worry about what's
alloc'ed?
JT
_______________________________________________
This mind intentionally left blank
_______________________________________________
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