일부 객관적인 C 코드를 사용하여이 메소드를 작성했으며 계측기에서 누설이 있음을 알려줍니다. 뿐만 아니라 무료 (문자 *) 충돌이 발생합니다 ...C 코드에서 메모리 누수가 발생했습니다.
도움이 될 것입니다.
주셔서 감사합니다 코드가 보유하고 있지 않습니다
NSArray *keys = @[@"@\"NSMutableArray\""];
//Init result
id result = object;
//Iterate every key
for (id key in [dict allKeys]) {
//Convert key to const char
const char * c =(const char*)malloc(sizeof(uint32_t));
c = [key cStringUsingEncoding:NSASCIIStringEncoding];
//Use c to see if the class has this property
if (class_getProperty([object class], c)) {
//get the property
objc_property_t property = class_getProperty([result class], c);
//Get the property name and type
const char *name = (const char*)malloc(sizeof(uint32_t));
const char *type = (const char*)malloc(sizeof(uint32_t));
name = property_getName(property);
type =property_copyAttributeValue(property, "T");
//Cast const char to string
NSString *pNameString = [NSString stringWithFormat:@"%s",name];
NSString *typeString = [NSString stringWithFormat:@"%s",type];
//Add relationships
if ([keys containsObject:typeString]) {
//Get array of objects
NSArray *relationship = [dict objectForKey:pNameString];
NSMutableArray *allSubObjects = [[NSMutableArray alloc]init];
//Parse each individual object
for (NSDictionary *relationshipObj in relationship) {
//Create class from relationship
Class class = NSClassFromString(pNameString);
//Create object
id sub = [self makeObject:[[class alloc]init] fromDictionary:relationshipObj];
[allSubObjects addObject:sub];
}
[result setValue:allSubObjects forKey:pNameString];
}else{
//If so set the property for the key
[result setValue:[dict objectForKey:key] forKey:key];
}
free((char*)name);
free((char*)type);
free(property);
}else{
//NSLog(@"%@ did not respond to : %@", result, key);
}
free((void*)c);
}
//Return result
return result;
나에게 C처럼 보이지 않는다 ... –
나는 그 C++, 비 객관적인 C stuff (const char *)라고 생각한다. –
어디에서 누출이보고 되었는가? 충돌이 어느 선에 있습니까? 더 많은 정보를 제공해 주셔야합니다. – Sebastian