iphone - 消除由于返回创建的变量而导致的内存泄漏

标签 iphone ios objective-c memory-management

以下是我遇到内存泄漏问题的代码片段。
enter image description here

这是第 3 个警告。

对象泄露:分配并存储到“strRespondData”中的对象是从名称(“httpConnection:postStr:”)不以“copy”、“mutableCopy”、“alloc”或“new”开头的方法返回的。这违反了 Cocoa 内存管理指南中给出的命名约定规则

*我的代码启用了 ARC。

最佳答案

您可以使用自动释放消息:

NSString *strRespondData = [[[NSString alloc] initWithData:responseData encoding:NSASCIIStringEncoding] autorelease];

您可以阅读说明here

如果您使用 ARC,则无需担心,ARC 会为您处理。

关于iphone - 消除由于返回创建的变量而导致的内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15242397/

相关文章:

ios - 将 Linphone 集成到自己的 iOS 项目中

iphone - 合并两个 UIImages 比 CGContextDrawImage 更快

iOS:NSNumberFormatter 从本地货币到双倍

iphone - 推迟 viewWillAppear 直到 webViewDidFinishLoad

iOS : push notification badge count not increase in this payload formate

android - react native : Dev Server IP iOS vs Android

ios - 如何停止滚动/拖动超出 UITableView 的边界?

ios - Objective-C 。这个 UIButton 图像有什么问题?

ios - 知道何时在 Apple Watch 模态界面 Controller 中单击取消按钮

iOS:UITableViewController——cellForRowAtIndexPath 单元格创建