【发布时间】:2013-10-02 07:45:19
【问题描述】:
你好,
我运行了 XCode 分析器 - 它告诉我以下两者都是潜在的内存泄漏。 我不确定为什么。 我这样声明了 midiDevices
@property (assign, nonatomic) NSMutableArray* midiDevices;
这是 openMidiIn 的代码
-(void)openMidiIn {
int k, endpoints;
CFStringRef name = NULL, cname = NULL, pname = NULL;
CFStringEncoding defaultEncoding = CFStringGetSystemEncoding();
MIDIPortRef mport = NULL;
MIDIEndpointRef endpoint;
OSStatus ret;
/* MIDI client */
cname = CFStringCreateWithCString(NULL, "my client", defaultEncoding);
ret = MIDIClientCreate(cname, NULL, NULL, &mclient);
if(!ret){
/* MIDI output port */
pname = CFStringCreateWithCString(NULL, "outport", defaultEncoding);
ret = MIDIInputPortCreate(mclient, pname, MidiWidgetsManagerReadProc, self, &mport);
if(!ret){
/* sources, we connect to all available input sources */
endpoints = MIDIGetNumberOfSources();
//NSLog(@"midi srcs %d\n", endpoints);
for(k=0; k < endpoints; k++){
endpoint = MIDIGetSource(k);
void *srcRefCon = endpoint;
MIDIPortConnectSource(mport, endpoint, srcRefCon);
}
}
}
if(name) CFRelease(name);
if(pname) CFRelease(pname);
if(cname) CFRelease(cname);
}
感谢您的帮助。
分析仪信息 这是有关进行一些更改的错误的更多信息。
【问题讨论】:
-
你需要阅读 Objective-C 中的内存管理和属性。简而言之,您不能将
assign用于类类型属性并期望它能够工作。 -
不应分配带有 assign 的属性,而是为其分配一个值 => midiDevices = otherArray.使用保留/强。
标签: ios memory memory-leaks