这段代码有什么问题,在这个块上创建了34个内存泄漏?

时间:2017-01-05 04:37:44

标签: ios swift memory-leaks

enter image description here enter image description here我不知道我在这个区块里做错了什么,但是在通过仪器>泄漏检查时,它显示了34个泄漏,有时在这个区块上有更少的泄漏,这是什么错误的,请与我分享您的专家意见,以了解泄密的原因。

public func getInspectionAddressCoordinates(requestMessage: InspectionServiceRequestMessage) -> (ServiceResponseMessage){


    if Global.shared.isConnected {

        let params = [
            "address": requestMessage.inspectionAddress.stringByReplacingOccurrencesOfString(" ", withString: "+", options: NSStringCompareOptions.CaseInsensitiveSearch, range: nil)
        ]
        let networkRequestMessage = RequestNetworkMessage(requestType: RequestType.GET, contentType: ContentType.ContentTypeHTML, url: MAP_URL, params: params)

        let networkResponseMessage = BaseNetwork().performNetworkTask(requestMessage: networkRequestMessage)

        switch networkResponseMessage.statusCode {
        case .Success:

            if let data = networkResponseMessage.data as? NSData {

                do {
                    let jsonObject: AnyObject = try NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers)

                    if let jsonDict = jsonObject as? [String: AnyObject] {
                        if let results = jsonDict["results"] as? [AnyObject] {
                            for dict in results {
                                if let geo = dict["geometry"] as? [String: AnyObject] {
                                    if let loc = geo["location"] as? [String: AnyObject] {
                                        if let lat = loc["lat"] as? Double {
                                            if let lon = loc["lng"] as? Double {
                                                print("\(lat), \(lon)")
                                                let msg = self.getSuccessResponseMessage("Inspection Status Updated")
                                                msg.data = ["lat":lat, "lon": lon]
                                                return msg
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
            } catch _ {
                    return self.getErrorResponseMessage("Unable to parse")
            }
            return self.getErrorResponseMessage("Unable to parse")

            }
            else {
                return self.getErrorResponseMessage("Unable to parse")
            }
        case .Failure:
            return self.getErrorResponseMessage("Network error in inspection status update request")
        case .Timeout:
            return self.getTimeoutErrorResponseMessage("Inspection status update request has been timed out")
        }
    }
    else  {
        return self.getErrorResponseMessage(ERROR_NO_NETWORK)
    }
}

0 个答案:

没有答案