Re: Can't keep from leaking memory
Re: Can't keep from leaking memory
- Subject: Re: Can't keep from leaking memory
- From: Ondra Cada <email@hidden>
- Date: Sat, 25 Jun 2005 22:32:09 +0200
Lee,
let me repeat the offending code, for a reference:
- (NSData*)someData {
NSData *someData = [[NSData alloc] initWithData:otherData];
if (someData == nil)
someData = [[NSData alloc] initWithData:someOtherData];
return [[someData retain] autorelease];
}
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.
That does seem to be the problem. However I can't think of any way
to code around this.
if it is, it would be a bug in NSData.
I seriously doubt it though: matter of fact, initWithData would
hardly ever return nil. Perhaps (I haven't tested!) if otherData is
nil too, in which case you can test for it easily (and in which case
you probably should not use initWithData: at all :))
Incidentally and to be frank, I did even not know there is an -
[NSData initWithData] method; myself, in such a case, I would use
copy. That would make sure nothing can leak (or fail otherwise) if
otherData is nil :))
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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