0

We are having some memory allocation issues. When I am run my app and come to a certain page, the Memory count is increased by 30mb each time I come to the page.

I have added IBOutlets as Weak and declared variables as ? (i.e. Optionals), though memory is not deallocating object and deinit() is not getting called when I am unloading my page.

My Code Below
———————————

Declaration

//[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)
}
dasdom
  • 13,975
  • 2
  • 47
  • 58
dhaval shah
  • 4,499
  • 10
  • 29
  • 42

1 Answers1

0

If deinit of your view controller is not called, then someone is holding a strong reference to it. Find the culprit.

BTW. It is probably not a good idea to play around with superviews. That could create all kinds of trouble.

gnasher729
  • 51,477
  • 5
  • 75
  • 98