【问题标题】:Objective-C on iPhone - use of NSOperationQueue and NSInvocationOperationiPhone 上的 Objective-C - NSOperationQueue 和 NSInvocationOperation 的使用
【发布时间】:2012-03-01 10:48:43
【问题描述】:

我有一个 UITableViewController,我正在使用来自 Web 服务的数据进行填充。在下载数据时,我使用 NSInvocationOperation 和 NSOperationQueue 在后台线程上运行 Web 服务调用,同时在 UI 上显示进度指示器。这一切都很好,但我只想确保我正确处理了这些对象。我的代码如下:

NSOperationQueue *backgroundTaskQueue = [[NSOperationQueue alloc] init];
NSInvocationOperation *webServiceOp = [[NSInvocationOperation alloc]
                                        initWithTarget:self
                                        selector:@selector(loadListDataOperation)
                                        object:nil];
[backgroundTaskQueue addOperation:webServiceOp];
[webServiceOp release];

我的内存管理知识告诉我应该在某个时候释放 backgroundTaskQueue,但不确定在哪里 - 它应该只是在 UITableViewController 的 dealloc() 方法中吗?

任何帮助表示赞赏,

乔纳森

【问题讨论】:

    标签: objective-c uitableview release nsoperation nsoperationqueue


    【解决方案1】:

    是的,如果您分配了队列,您应该释放它。 dealloc 方法将是一个理想的地方。

    【讨论】:

      猜你喜欢
      • 2011-04-13
      • 2017-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-24
      • 2010-11-09
      • 1970-01-01
      相关资源
      最近更新 更多