gpt4 book ai didi

iphone - ASIHTTPRequest 的问题

转载 作者:行者123 更新时间:2023-11-28 18:43:21 25 4
gpt4 key购买 nike

我正在尝试使用 wordpress api,但我的请求遇到未知问题:第一个请求完美无缺,但第二个请求崩溃了。我的代码:

//Response from request, which was before
NSString *responseString = [request responseString];
SBJsonParser *jsonParser = [SBJsonParser new];
NSDictionary *dict = (NSDictionary*)[jsonParser objectWithString:responseString];
[jsonParser release];
int count = 10
int loadingNow = 1;
while (loadingNow <= count) {
NSDictionary *currentPostDict = (NSDictionary *)[fullPosts objectAtIndex:(loadingNow - 1)];
NSString *currentSlug = (NSString *)[currentPostDict objectForKey:@"slug"];
if (loadingNow == 1) {
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.smartfiction.ru/api/get_post/?slug=%@", currentSlug]];
NSLog(@"url: %@", url);
ASIHTTPRequest *requestNew = [ASIHTTPRequest requestWithURL:url];
[requestNew setDelegate:self];
[requestNew setDidFinishSelector:@selector(requestDidFinishForThreadID:)];
[requestNew setTag:1];
[requestNew startAsynchronous];
[url release];
}
}

我的网址如下所示: http://www.smartfiction.ru/api/get_post/?slug=best_friend

错误的地方: //在ASIHTTPRequest.m中 NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:[[self url] absoluteURL]];

最佳答案

解决方案:

你应该摆脱这一行......

[url release];

发生了什么?

这就是问题所在...

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.smartfiction.ru/api/get_post/?slug=%@", currentSlug]];

您在这里所做的没有任何问题。但是这个方法返回一个自动释放的 NSURL。这意味着一旦您的 url 变量超出范围,autoReleasePool 就可以公平地在应用程序下一次运行它的下一个周期时释放它。

当您使用 [url release] 手动释放它时,它的保留计数为零,很快就会被释放。然后下次您尝试访问它时,它不再存在,并且操作系统会关闭您。

那么,这里发生了什么?

如果您通过向类发送 alloc 消息来创建一个对象,则您“拥有”该对象并负责在适当的时间释放它。除此之外,当您使用这些类构造函数之一时,该对象已经自动释放,您无需负责释放它。

通常,您应该将每个 allocreleaseautorelease 配对。

关于iphone - ASIHTTPRequest 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8451700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com