Re: Can't keep from leaking memory
Re: Can't keep from leaking memory
- Subject: Re: Can't keep from leaking memory
- From: Lee Morgan <email@hidden>
- Date: Sat, 25 Jun 2005 16:42:00 -0400
On Jun 25, 2005, at 9:45 AM, Tony S. Wu wrote: in your code, someData should never be nil. even if otherData is nil, someData would only be an empty NSData object, but it still is not nil.
only time it will be nil is if its super class fail to initialize. (someone corrects me if i am wrong)
and if that's the case, the code should never go into the if loop, and without the retain message it still should be OK.
I'm sure when I init it with nil data it becomes nil, since my if() returns true and I enter the condition. so, where are you checking if your application is leaking memory?
MallocDebug, this method is connected to a button - makes it easy to test and see that I leak NSAllocateObject (or the class leaks if I use dataWIth...) Also I've done some crude state & retain count logging. under what circumstances do you expect the if loop be executed? how about copy-and-pasting your code?
Well, it's not exactly copy&paste since the code is spread out, but here goes...
NSData *data = "">[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:urlString]]; if (data == nil) { data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:otherURLstring]]; } return [data autorelease]; i think you might want to check if otherData is nil, instead of checking someData also, why not use NSData's + dataWithData: class method instead?
I've tried many different methods, including class connivence methods - leaks just the same.
- Lee
|
_______________________________________________
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