私には2つの問題があります。私は辞書を作成して、それを合成したグローバル変数に保存します。私はそれを割り当てるだけで、別のメソッドからアクセスしようとすると、その空で、私がコピーを使用すると、メモリがリークします。iOS NSDictionaryコピーメモリリーク
私はそれを割り当てることができます。NSStringのような "より単純な"オブジェクトがあれば動作しますが、NSDictionaryではなぜ動作しませんか?
.H:
@interface ClassIHate : UIViewController{
NSDictionary *postBuild;
}
@property (nonatomic, retain) NSDictionary *postBuild;
-(void)prepData;
@end
- 私はそれだけでは私の問題であるとして、変数ポストビルドを使用するクラスを含みます。ここで問題になる可能性が何の.m
@implementation ClassIHate
@synthesize postBuild;
- (void)viewDidUnload {
postBuild = nil;
}
- (void)dealloc {
[postBuild release];
[super dealloc];
}
-(void)prepData{
NSInteger i = 0;
NSMutableDictionary *_postBuild = [[NSMutableDictionary alloc]initWithCapacity:0];
for (NSString *key in self.keys) {
NSMutableArray *array = [ops valueForKey:key];
NSInteger j = 0;
for (MyDataType *object in array) {
NSString *abc = object.abc;
UITableViewCell *cell = [table cellForRowAtIndexPath:[NSIndexPath indexPathForRow:j inSection:i]];
UITextView *tv = (UITextView *)cell.accessoryView;
NSString *mon = tv.text;
NSString *monFormat = [[NSString stringWithFormat:@"%.2lf",[mon doubleValue]]stringByReplacingOccurrencesOfString:@"." withString:@","];
[_postBuild setObject:monFormat forKey:abc];
j++;
}
i++;
}
//postBuild = _postBuild; //Empty when called in other method
postBuild = [_postBuild copy]; //Leaks memory
[_postBuild release];
}
-(void)realizarOperaciones{
//DO STUFF
NSArray *postKeys = [postBuild allKeys]; //postBuild is nil if I dont use copy, leaks memory if I do.
//DO STUFF
}
? ありがとう、ステファノ。
これはグローバル変数ではなく、インスタンス変数です。合成された変数でもありません。あなたの例ではメソッド定義だけが合成されます。 –