ASIHTTPRequest 在第二次调用时崩溃
我有一个视图控制器,它有一个按钮,可以触发向 Web 服务发送请求的方法(使用 JSON)。触发的方法创建一个 ASIFormDataRequest
对象并将 JSON 字符串成功发送到 Web 服务。我知道这是成功的,因为我已将 NSLogs 放入 requestFinished 方法中,并且它们正在写入控制台(另外,Web 服务正在正确处理数据)。
成功执行后,我再次点击按钮(是的,将相同的数据发送到网络服务)。应用程序崩溃。
[53166:6203] *** -[CFURL release]:消息发送到已释放的实例 0x4c5dd00
[切换到进程53166线程0x6203]
[切换到进程 53166 线程 0x6203]
XCode 然后突出显示 ASIHTTPRequests
runRequests 方法中的 CFRunLoop()
函数> 类。
我尝试在 requestFinished
方法中调用 [request cancel];
,但这也不起作用。
I have a view controller that has a button that triggers a method to send a request to a web service (using JSON). The method triggered creates a ASIFormDataRequest
object and sends the JSON string successfully to the web service. I know that this is successful because I have put NSLogs in the requestFinished
method and they are writing out to the console (plus, the web service is processing the data properly).
After this has successfully executed I hit the button again (yes, sending the same data to the web service). The app crashes.
[53166:6203] *** -[CFURL release]: message sent to deallocated instance 0x4c5dd00
[Switching to process 53166 thread 0x6203]
[Switching to process 53166 thread 0x6203]
XCode then highlights the CFRunLoop()
function within the runRequests
method in the ASIHTTPRequests
class.
I have tried calling [request cancel];
in the requestFinished
method, but that doesn't work either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够弄清楚这一点。由于我对 iOS 开发还是个新手,对内存管理还不太了解,所以答案有点简单。但基本上,我在我的方法中释放了一个 NSURL 变量。我一注释掉它,它就起作用了。
作为旁注,我还修改了我的代码以利用 NSOperationQueue,如下所述: http ://allseeing-i.com/ASIHTTPRequest/How-to-use#using_a_queue
I was able to figure this out. As I'm still new to iOS dev and getting my head around the memory management, the answer is a little light. But basically, I was releasing an NSURL variable within my methods. As soon as I commented this out, it works.
As a side note, I also modified my code to leverage an NSOperationQueue as mentioned here: http://allseeing-i.com/ASIHTTPRequest/How-to-use#using_a_queue