我们遇到了一些内存分配问题。当我运行应用程序并进入某个页面时,每次进入该页面时,内存计数都会增加30mb。
我已将IBOutlets添加为弱,并将变量声明为?(即Optionals),但在卸载页面时,内存没有释放对象,deinit()
也没有被调用。
下面的我的代码
----------------------
申报
//[Mapped Outlet With Front End]
@IBOutlet weak var testInd: UIActivityIndicatorView!
@IBOutlet weak var uiPendingView: UIView!
@IBOutlet weak var uiDraftView: UIView!
@IBOutlet weak var propertyListingTableView: UITableView!
@IBOutlet weak var uiCompletedView: UIView!
@IBOutlet weak var propertiesMap: MKMapView!
@IBOutlet weak var btnSynch: UIButton!
@IBOutlet weak var lblPendingStatus: UILabel!
@IBOutlet weak var lblDraftStatus: UILabel!
@IBOutlet weak var lblCompleteStatus: UILabel!
@IBOutlet weak var networkLabel: UILabel!
@IBOutlet weak var tableEmtyLabel: UILabel!
@IBOutlet weak var lblPropertyLabel: UILabel!
@IBOutlet weak var lblPendingLabel: UILabel!
@IBOutlet weak var lblDraftLabel: UILabel!
@IBOutlet weak var lblCompletedLabel: UILabel!
@IBOutlet weak var segmentControllerSynch: UISegmentedControl!
@IBOutlet weak var googleMapView: GMSMapView!
@IBOutlet weak var propertyLabelView: UIView!
//[Local variable declaration]
var annotation: CustomPointAnnotation?
var annotationArray : [CustomPointAnnotation]?
var properties:[Property] = [Property]()
var tempProperties:[Property] = [Property]()
var pushProperties:[Property] = [Property]()
var getProperties:[Property] = [Property]()
var draftProperties:[Property] = [Property]()
var failedProperties:[Property] = [Property]()
var property: Property?
var company: Company?
var companies: [Company]?
var allProperties: [Property]?
var xmlElementData : NSData!
var filePath:NSString?
var xmlParseString: NSString?
var xmlNSData: NSData?
var pendingFilterTick = false
var draftFilterTick = false
var compeletdFilterTick = false
var fromPopover = false
var errorStr: String?
var tokenStr: String?
var resultDict: NSDictionary?
var sortingImg : UIImage = UIImage(named: "Sorting")!
var menuImg : UIImage = UIImage(named: "Slider")!
var leftLogo : UIImage = UIImage(named: "logo")!
var sortingBtn : UIBarButtonItem?
var menuBtn : UIBarButtonItem?
var leftBtn : UIBarButtonItem?
var emptyView: UIView!
var actInd: UIActivityIndicatorView?
var container: UIView?
var lblProcess: UILabel?
var loadingView: UIView?
let nsFileManager = NSFileManager.defaultManager()
//[Local class declaration]
var constants = Constants()
var parser = XMLParser()
var utility = Utility()
var fileMgr = FileManagement()
var xmlParser = XMLParser()
var netUtil = NetworkUtil()
var dict:Dictionary<String,String> = Dictionary<String,String>()
let appDelegate = UIApplication.sharedApplication().delegate as? AppDelegate
var unitCount = 0
var dateUtil = DateUtils()
var synchCompanies:[Company]?
var controllerUtil = ControllerUtil()
var errorHandling = ErrorHandling()
//[Variable declaration for the Google map]
var locationManager = CLLocationManager()
var didFindMyLocation = false
override func viewDidDisappear(animated: Bool) {
super.viewDidDisappear(animated)
print("viewDidDisappear")
if let superView = self.view.superview
{
superView.removeFromSuperview()
}
fileMgr.deallocateReferences(xmlNSData!)
// fileMgr: FileManagement = nil
tempProperties = []
pushProperties = []
getProperties = []
draftProperties = []
failedProperties = []
// testInd = nil
// uiPendingView = nil
// uiDraftView = nil
// propertyListingTableView = nil
// uiCompletedView = nil
// propertiesMap = nil
// btnSynch = nil
// lblPendingStatus = nil
// lblDraftStatus = nil
// lblCompleteStatus = nil
// networkLabel = nil
// tableEmtyLabel = nil
// lblPropertyLabel = nil
// lblPendingLabel = nil
// lblDraftLabel = nil
// lblCompletedLabel = nil
// segmentControllerSynch = nil
// googleMapView = nil
// propertyLabelView = nil
}
deinit{
print("DEINIT")
googleMapView.removeObserver(self, forKeyPath: "myLocation", context: nil)
}
如果没有调用视图控制器的deinit,那么有人持有对它的强引用。找出罪魁祸首。
顺便说一句。玩超视图可能不是个好主意。这可能会制造各种各样的麻烦。