第二次映射响应时,RestKit会在不释放内存的情况下继续分配内存。
示例
JSON:
// http://example.com/api/shop/
{
{
"id": 1,
"title": "some shop",
"items": [
{
"id": 1,
"name": "some item"
},
...
{
"id": 10000,
"name": "some other item"
}
]
}
}
响应映射/描述符
let itemMapping = RKEntityMapping(forEntityForName: "Item", inManagedObjectStore: RKManagedObjectStore.defaultStore())
itemMapping.addAttributeMappingsFromDictionary([
"title":"title",
"id": "iID"
])
itemMapping.identificationAttributes = ["iID"]
let shopMapping = RKEntityMapping(forEntityForName: "Shop", inManagedObjectStore: RKManagedObjectStore.defaultStore())
shopMapping.addAttributeMappingsFromDictionary([
"title":"title",
"id": "sID"
])
shopMapping.identificationAttributes = ["sID"]
shopMapping.addPropertyMapping(RKRelationshipMapping(fromKeyPath: "items", toKeyPath: "items", withMapping: itemMapping))
let shopResponseDescriptor = RKResponseDescriptor(mapping: shopMapping, method: RKRequestMethod.Any, pathPattern: "/api/shop/", keyPath: nil, statusCodes: RKStatusCodeIndexSetForClass(RKStatusCodeClass.Successful))
RKObjectManager.sharedManager().addResponseDescriptorsFromArray(
[
shopResponseDescriptor
]
)
这会一直分配内存,直到应用程序崩溃。
使用乐器我能够确定应用程序在分配超过650mb时崩溃,主要包括:
__NSDictionary
,大小:226mb,负责的来电者:[NSManagedObject dictionaryWithValuesForKeys:]
__NSSet
,大小:168mb,负责的来电者: - [RKManagedObjectMappingOperationDataSource mappingOperation:targetObjectForRepresentation:withMapping:inRelationship:]
__NSArray
大小:112mb,负责的来电者:-[RKManagedObjectMappingOperationDataSource mappingOperation:targetObjectForRepresentation:withMapping:inRelationship:]
即使响应通常不会包含已存储在设备上的那么多对象,以防许多对象发生更改,但可能会发生这样的事情并使应用程序崩溃。有没有人遇到这个问题并且有解决方法吗?