Re: Can't keep from leaking memory
Re: Can't keep from leaking memory
- Subject: Re: Can't keep from leaking memory
- From: Tomasz Kukielka <email@hidden>
- Date: Sat, 25 Jun 2005 16:11:23 -0700
On Jun 25, 2005, at 2:58 PM, email@hidden wrote:
- (NSData*)someData {
NSData *someData = [[NSData alloc] initWithData:otherData];
if (someData == nil)
someData = [[NSData alloc] initWithData:someOtherData];
return [[someData retain] autorelease];
}
Don't retain the allocated someData. After allocation you have retain
count of 1. Then you retain it and you have retain count 2. When
autorelease does its job later it will decrease the retain count to 1
but the memory will not be freed. You need to go down to 0 to get the
resources freed.
HTH,
Tom
_______________________________________________
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