Do you need to release NSData?
-(void) func1: (NSData*) somedata
{
//Processing somedata ..开发者_如何学C..
[somedata release]; //is it necessay?
}
You shouldnt release somedata
inside your method.
NSData *somedata = [[NSData alloc] init];
func1(somedata);
[somedata release];
Assumptions:
- func1 runs on same thread
In this case, no, you should not release your object. You're not the "owner". As a rule of thumb, you need to release an object once you're done with it only if:
- You allocated it via
[MyClass alloc]
, as in[[MyClass alloc] init]
or[[MyClass alloc] initWithFoo:foo bar:baz]
. - You got a copy via
[someObject copy]
or[someObject mutableCopy]
. - You have retained it before.
You should consider releasing it If you are retaining it in this case. But I am not sure because your question does not provide any idea whether a release is required or not. But generally you will release
objects if you take ownership of it.
精彩评论