【发布时间】:2011-12-14 16:27:16
【问题描述】:
使用“分析”,在 dealloc 中我得到: 调用者此时不拥有的对象的引用计数减少不正确
#import <AVFoundation/AVFoundation.h>
@interface XYZViewController : UIViewController
@property (retain) AVAudioRecorder *recorder;
@end
@implementation XYZViewController
@synthesize recorder;
- (void) dealloc
{
[self.recorder release];
[super dealloc];
}
- (void) viewDidLoad
{
NSURL *url = [NSURL fileURLWithPath:@"/dev/null"];
NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat: 44100.0], AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
[NSNumber numberWithInt: AVAudioQualityMax], AVEncoderAudioQualityKey,
nil];
NSError *error;
self.recorder = [[[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error] autorelease];
}
@end
这是否意味着我不应该释放它?
此外,我尝试“分析”代码,但无论如何我都会从[[[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error] autorelease] 得到内存泄漏。
【问题讨论】:
标签: objective-c release avfoundation memory-leaks avaudiorecorder