- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用 substringWithRange 时出现泄漏,如下面的代码行所示。我虽然所有这些函数都是自动释放的,你不需要手动分配/释放它们。
NSCFString 是被泄露的对象。
我做错了什么?
aLTR.drew = [substring substringWithRange:NSMakeRange(match.location+1, (match2.location-(match.location+1)))];
我想做的是提取一个子字符串并将其存储到我的存储类中。下面的代码。
#import <Foundation/Foundation.h>
@interface LeagueTableRow : NSObject
{
NSString *_teamName;
NSString *_played;
NSString *_won;
NSString *_drew;
NSString *_lost;
NSString *_goalsFor;
NSString *_goalsAgainst;
NSString *_points;
}
@property(nonatomic, copy) NSString *teamName;
@property(nonatomic, copy) NSString *played;
@property(nonatomic, copy) NSString *won;
@property(nonatomic, copy) NSString *drew;
@property(nonatomic, copy) NSString *lost;
@property(nonatomic, copy) NSString *goalsFor;
@property(nonatomic, copy) NSString *goalsAgainst;
@property(nonatomic, copy) NSString *points;
-(id)init;
@end
#import "LeagueTableRow.h"
@implementation LeagueTableRow
@synthesize teamName = _teamName;
@synthesize played = _played;
@synthesize won = _won;
@synthesize drew = _drew;
@synthesize lost = _lost;
@synthesize goalsFor = _goalsFor;
@synthesize goalsAgainst = _goalsAgainst;
@synthesize points = _points;
-(id)init
{
self = [super init];
return self;
}
-(void) dealloc
{
self.teamName = nil;
self.played = nil;
self.won = nil;
self.drew = nil;
self.lost = nil;
self.goalsFor = nil;
self.goalsAgainst = nil;
self.points = nil;
[super dealloc];
}
@end
虽然我正在安静、整洁地管理内存,但我还是感到有些泄漏。
感谢您的建议和提示。-代码
最佳答案
在你的 dealloc 中,只需释放所有字符串 ivars:
[_teamName release];
etc...
或者,您可以:
[self.teamName release];
etc...
在这种情况下,我更喜欢直接使用 ivars。
关于iphone - 从 substringWithRange 获取泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6982491/
我在使用 substringWithRange 时出现泄漏,如下面的代码行所示。我虽然所有这些函数都是自动释放的,你不需要手动分配/释放它们。 NSCFString 是被泄露的对象。 我做错了什么?
仪器通知我我正在从以下代码片段中泄漏内存 for (int x=0; x ([substring length])) { } substring = [substring substringFromI
我遇到了非拉丁字符集问题,我需要在执行 .substringWithRange 之前检查范围是否在范围内。这看起来真的很容易,但我找不到这样做的方法。 给定一个范围: let lastCharRang
当我对有问题的字符串进行硬编码并尝试使用 substringWithRange 时,它工作得很好。但是当我将用户输入作为 char 并将其转换为 NSString 时,它会抛出 NSRange 异
我有Xcode 7 gm,带有swift 2.0,等效于 Let myNSString = "full text container" myNSString.substringWithRange(NS
我正在开发一个 OS X 应用程序,运行 XCode 6.4 和 Yosemite。将问题简化为几行代码,我使用 substringWithRange 来提取子字符串并获取一个 18 个字符长的字符串
通过 X-Code 中的 Leaks 工具运行我的程序,它指出这个函数是我内存泄漏的主要原因。 + (NSMutableArray *) getColumns:(NSString *) dev
我在 iOS 4 中遇到了一个有趣的新错误: -[NSCFString substringWithRange:]: Invalid range {11, 4294967295}; this will
我仅从一位用户那里收到了30多个崩溃报告。没有人显示相同的行为。通常,我可以找出问题所在,因为总是有对我的代码的引用,但是没有引用。 它们都是来自类型: Exception Type: EXC_CR
我不得不说,对于“现代”语言,Swift 肯定会在指定范围以捕获子字符串方面大吃一顿。我的问题:有没有办法创建一个使用 Range(0...4)或者确实是一种转换结果(类型 )的方法,以便它可以与
以下代码使我的应用程序在第 3 行崩溃,没有出现我会识别或知道如何处理的错误。关于我做错了什么有什么想法吗? NSInteger *match = [str1 intValue] + [str2 in
我试图在选项字符串上调用 substringWithRange,但经过多次实验后我仍然无法编译它: var mdn:String? var subscriber = CTSubscriber() va
我目前使用带有起始索引和长度的 substringWithRange(): let str = "Hello World" let index = 0 let length = 3 str.subst
我必须检查给定 NSString 中的每个字符是否符合某种条件。 当字符串包含以 4 个字节(UTF-8 编码)表示的字符时,结果不是我期望的字符。 NSString* oneCharString =
假设我在 NSString“foo”上传递了 (location: 5, length: 50) 的 NSRange,这个范围显然不存在。 有没有办法说[string rangeExists:NSRa
我正在尝试从字符串中获取第一个字符。这应该很容易,但我不能在 Swift 2.0(使用 Xcode beta 6)中做。 Get nth character of a string in Swift
我正在尝试一些我在 natashatherobot.com 上找到的简单代码. var str = "Hello, playground" let rangeOfHello = Range(start
当我尝试从一个较大的字符串中提取一个字符串时,它给我一个范围或索引越界错误。我可能忽略了这里非常明显的东西。谢谢。 NSString *title = [TBXML textForElement:ti
我还没有弄清楚如何在 Swift 中获取 String 的子字符串: var str = “Hello, playground” func test(str: String) -> String {
当我尝试在 UISearchBar 上执行撤消操作时,我的应用程序崩溃了。在我的应用程序中,我有代码来防止在搜索栏上输入“%”符号,为此它在 textDidChange 方法中将 % 替换为 @"",
我是一名优秀的程序员,十分优秀!