------Java培训、Android培训、iOS培训、.Net培训、期待与您交流! -------
Q: Is the delegate for a CAAnimation retained?
A: Yes it is!! This is one of the rare exceptions to memory management rules.
Q: What happens when the following code executes?
Ball *ball = [[[[Ball alloc] init] autorelease] autorelease];
A: It will crash because it’s added twice to the autorelease pool and when it dequeued the autorelease pool calls release more than once.
Q: Outline the class hierarchy for a UIButton until NSObject.
A: UIButton inherits from UIControl, UIControl inherits from UIView, UIView inherits from UIResponder, UIResponder inherits from the root class NSObject
Q: Explain the difference between NSOperationQueue concurrent and non-concurrent.
A: In the context of an NSOperation object, which runs in an NSOperationQueue, the terms concurrent and non-concurrent do not necessarily refer to the side-by-side execution of threads. Instead, a non-concurrent operation is one that executes using the environment that is provided for it while a concurrent operation is responsible for setting up its own execution environment.
Q: Implement your own synthesized methods for the property NSString *title.
A: Well you would want to implement the getter and setter for the title object. Something like this:
-(NSString *)title{
return title;
}
- (void) setTitle:(NSString*) newTitle{
if (newTitle !=title) {
[title release];
title = [newTitle retain]; / or copy, depending on your needs
}
}
Q: Implement the following methods: retain, release, autorelease.
A:
-(id)retain{
NSIncrementExtraRefCount(self);
retain self;
}
-(void) release {
if (NSDecremetExtraRefCountWasZero(self)) {
NSDeallocateObject(self);
}
}
-(id)auotrelease {
// add the object to the autorelease pool
[NSAutoreleasePool addObject:self];
return self;
}