开发者

How does NSURLCache work in iOS 4?

When I learn NSURLCache documentation I can't find many important notes. I found that many topics in web complain that NSURLConnection that use NSURLCache had memory leaks. When I tried to write some application for iOS 4.3 I found that MSURLCache have some strange behavior.

In application:didFinishLaunchingWithOptions: I set instance of NSURLCache with memory capacity 1开发者_如何学Python0MB, init NSURLRequest with NSURLRequestUseProtocolCachePolicy but I can't recieve connection:willCacheResponse: message in my NSURLConnection delegate. When I checked memory capacity in different points of my application, it was 0MB. Why? May be Apple fix some memory leaks by setting NSURLCache memory capacity to 0? I created custom NSURLCache and overrided setMemoryCapacity: method by this:

-(void)setMemoryCapacity:(NSUInteger)memoryCapacity {
    if (memoryCapacity > 0) {
        [super setMemoryCapacity:memoryCapacity];
    }
    else {
        NSLog(@"zero here");
    }
}

Then I started to debug. There is some input text in my app, where user put some url. New setMemoryCapacity: method has been called twice: in my app delegate, when I set capacity to 10MB and (it is very interesting) when user set focus to text input (parameter of memoryCapacity was 0 and I recieve "zero here" string in log). After that I recieved connection:willCacheResponse: messages to NSURLConnection delegate. It was very strange. I can't understand why. I can't find things in manual about this. Do you have some thoughts?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜